本文整理汇总了C++中SAMPLE_SIZE函数的典型用法代码示例。如果您正苦于以下问题:C++ SAMPLE_SIZE函数的具体用法?C++ SAMPLE_SIZE怎么用?C++ SAMPLE_SIZE使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SAMPLE_SIZE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BlockArray
BlockArray *Sequence::Blockify(samplePtr buffer, sampleCount len)
{
BlockArray *list = new BlockArray();
list->Alloc(10);
if (len == 0)
return list;
int num = (len + (mMaxSamples - 1)) / mMaxSamples;
for (int i = 0; i < num; i++) {
SeqBlock *b = new SeqBlock();
b->start = i * len / num;
int newLen = ((i + 1) * len / num) - b->start;
samplePtr bufStart = buffer + (b->start * SAMPLE_SIZE(mSampleFormat));
b->f = mDirManager->NewSimpleBlockFile(bufStart, newLen, mSampleFormat);
list->Add(b);
}
return list;
}
示例2: memset
/// Reads the specified data from the aliased file, using libsndfile,
/// and converts it to the given sample format.
///
/// @param data The buffer to read the sample data into.
/// @param format The format to convert the data into
/// @param start The offset within the block to begin reading
/// @param len The number of samples to read
int PCMAliasBlockFile::ReadData(samplePtr data, sampleFormat format,
sampleCount start, sampleCount len)
{
SF_INFO info;
if(!mAliasedFileName.IsOk()){ // intentionally silenced
memset(data,0,SAMPLE_SIZE(format)*len);
return len;
}
wxFile f; // will be closed when it goes out of scope
SNDFILE *sf = NULL;
{
Maybe<wxLogNull> silence{};
if (mSilentAliasLog)
silence.create();
memset(&info, 0, sizeof(info));
if (f.Exists(mAliasedFileName.GetFullPath())) { // Don't use Open if file does not exits
if (f.Open(mAliasedFileName.GetFullPath())) {
// Even though there is an sf_open() that takes a filename, use the one that
// takes a file descriptor since wxWidgets can open a file with a Unicode name and
// libsndfile can't (under Windows).
ODManager::LockLibSndFileMutex();
sf = sf_open_fd(f.fd(), SFM_READ, &info, FALSE);
ODManager::UnlockLibSndFileMutex();
}
}
if (!sf){
memset(data, 0, SAMPLE_SIZE(format)*len);
silence.reset();
mSilentAliasLog = TRUE;
// Set a marker to display an error message for the silence
if (!wxGetApp().ShouldShowMissingAliasedFileWarning())
wxGetApp().MarkAliasedFilesMissingWarning(this);
return len;
}
}
mSilentAliasLog=FALSE;
ODManager::LockLibSndFileMutex();
sf_seek(sf, mAliasStart + start, SEEK_SET);
ODManager::UnlockLibSndFileMutex();
SampleBuffer buffer(len * info.channels, floatSample);
int framesRead = 0;
if (format == int16Sample &&
!sf_subtype_more_than_16_bits(info.format)) {
// Special case: if the file is in 16-bit (or less) format,
// and the calling method wants 16-bit data, go ahead and
// read 16-bit data directly. This is a pretty common
// case, as most audio files are 16-bit.
ODManager::LockLibSndFileMutex();
framesRead = sf_readf_short(sf, (short *)buffer.ptr(), len);
ODManager::UnlockLibSndFileMutex();
for (int i = 0; i < framesRead; i++)
((short *)data)[i] =
((short *)buffer.ptr())[(info.channels * i) + mAliasChannel];
}
else {
// Otherwise, let libsndfile handle the conversion and
// scaling, and pass us normalized data as floats. We can
// then convert to whatever format we want.
ODManager::LockLibSndFileMutex();
framesRead = sf_readf_float(sf, (float *)buffer.ptr(), len);
ODManager::UnlockLibSndFileMutex();
float *bufferPtr = &((float *)buffer.ptr())[mAliasChannel];
CopySamples((samplePtr)bufferPtr, floatSample,
(samplePtr)data, format,
framesRead, true, info.channels);
}
ODManager::LockLibSndFileMutex();
sf_close(sf);
ODManager::UnlockLibSndFileMutex();
return framesRead;
}
示例3: wxASSERT
// This only decides if we must dither at all, the dithers
// are all implemented using macros.
void Dither::Apply(enum DitherType ditherType,
const samplePtr source, sampleFormat sourceFormat,
samplePtr dest, sampleFormat destFormat,
unsigned int len, unsigned int stride /* = 1 */)
{
unsigned int i;
// This code is not designed for 16-bit or 64-bit machine
wxASSERT(sizeof(int) == 4);
wxASSERT(sizeof(short) == 2);
// Check parameters
wxASSERT(source);
wxASSERT(dest);
wxASSERT(len >= 0);
wxASSERT(stride > 0);
if (len == 0)
return; // nothing to do
if (sourceFormat == destFormat)
{
// No need to dither, because source and destination
// format are the same. Just copy samples.
unsigned int srcBytes = SAMPLE_SIZE(destFormat);
if (stride == 1)
memcpy(dest, source, len * srcBytes);
else
{
samplePtr s = source;
samplePtr d = dest;
for (i = 0; i < len; i++)
{
memcpy(d, s, srcBytes);
s += stride * srcBytes;
d += srcBytes;
}
}
} else
if (destFormat == floatSample)
{
// No need to dither, just convert samples to float.
// No clipping should be necessary.
float* d = (float*)dest;
if (sourceFormat == int16Sample)
{
short* s = (short*)source;
for (i = 0; i < len; i++, d++, s+= stride)
*d = FROM_INT16(s);
} else
if (sourceFormat == int24Sample)
{
int* s = (int*)source;
for (i = 0; i < len; i++, d++, s+= stride)
*d = FROM_INT24(s);
} else {
wxASSERT(false); // source format unknown
}
} else
if (sourceFormat == int16Sample && destFormat == int24Sample)
{
// Special case when promoting 16 bit to 24 bit
short* s = (short*)source;
int* d = (int*)dest;
for (i = 0; i < len; i++)
{
*d = ((int)*s) << 8;
s += stride;
d++;
}
} else
{
// We must do dithering
switch (ditherType)
{
case none:
DITHER(NoDither, dest, destFormat, source, sourceFormat, len, stride);
break;
case rectangle:
DITHER(RectangleDither, dest, destFormat, source, sourceFormat, len, stride);
break;
case triangle:
DITHER(TriangleDither, dest, destFormat, source, sourceFormat, len, stride);
break;
case shaped:
Reset(); // reset shaped dither filter for this new conversion
DITHER(ShapedDither, dest, destFormat, source, sourceFormat, len, stride);
break;
default:
wxASSERT(false); // unknown dither algorithm
}
}
}
示例4: memset
/// Read the data portion of the block file using libsndfile. Convert it
/// to the given format if it is not already.
///
/// @param data The buffer where the data will be stored
/// @param format The format the data will be stored in
/// @param start The offset in this block file
/// @param len The number of samples to read
int LegacyBlockFile::ReadData(samplePtr data, sampleFormat format,
sampleCount start, sampleCount len)
{
SF_INFO info;
memset(&info, 0, sizeof(info));
switch(mFormat) {
case int16Sample:
info.format =
SF_FORMAT_RAW | SF_FORMAT_PCM_16 | SF_ENDIAN_CPU;
break;
default:
case floatSample:
info.format =
SF_FORMAT_RAW | SF_FORMAT_FLOAT | SF_ENDIAN_CPU;
break;
case int24Sample:
info.format = SF_FORMAT_RAW | SF_FORMAT_PCM_32 | SF_ENDIAN_CPU;
break;
}
info.samplerate = 44100; // Doesn't matter
info.channels = 1;
info.frames = mLen + (mSummaryInfo.totalSummaryBytes /
SAMPLE_SIZE(mFormat));
wxFile f; // will be closed when it goes out of scope
SNDFILE *sf = NULL;
if (f.Open(mFileName.GetFullPath())) {
// Even though there is an sf_open() that takes a filename, use the one that
// takes a file descriptor since wxWidgets can open a file with a Unicode name and
// libsndfile can't (under Windows).
sf = sf_open_fd(f.fd(), SFM_READ, &info, FALSE);
}
{
Maybe<wxLogNull> silence{};
if (mSilentLog)
silence.create();
if (!sf){
memset(data, 0, SAMPLE_SIZE(format)*len);
mSilentLog = TRUE;
return len;
}
}
mSilentLog=FALSE;
sf_count_t seekstart = start +
(mSummaryInfo.totalSummaryBytes / SAMPLE_SIZE(mFormat));
sf_seek(sf, seekstart , SEEK_SET);
SampleBuffer buffer(len, floatSample);
int framesRead = 0;
// If both the src and dest formats are integer formats,
// read integers from the file (otherwise we would be
// converting to float and back, which is unneccesary)
if (format == int16Sample &&
sf_subtype_is_integer(info.format)) {
framesRead = sf_readf_short(sf, (short *)data, len);
}else if (format == int24Sample &&
sf_subtype_is_integer(info.format)) {
framesRead = sf_readf_int(sf, (int *)data, len);
// libsndfile gave us the 3 byte sample in the 3 most
// significant bytes -- we want it in the 3 least
// significant bytes.
int *intPtr = (int *)data;
for( int i = 0; i < framesRead; i++ )
intPtr[i] = intPtr[i] >> 8;
} else {
示例5: LockDeleteUpdateMutex
bool Sequence::Delete(sampleCount start, sampleCount len)
{
if (len == 0)
return true;
if (len < 0 || start < 0 || start >= mNumSamples)
return false;
//TODO: add a ref-deref mechanism to SeqBlock/BlockArray so we don't have to make this a critical section.
//On-demand threads iterate over the mBlocks and the GUI thread deletes them, so for now put a mutex here over
//both functions,
LockDeleteUpdateMutex();
unsigned int numBlocks = mBlock->Count();
unsigned int newNumBlocks = 0;
unsigned int b0 = FindBlock(start);
unsigned int b1 = FindBlock(start + len - 1);
int sampleSize = SAMPLE_SIZE(mSampleFormat);
// Special case: if the samples to delete are all within a single
// block and the resulting length is not too small, perform the
// deletion within this block:
if (b0 == b1 && mBlock->Item(b0)->f->GetLength() - len >= mMinSamples) {
SeqBlock *b = mBlock->Item(b0);
sampleCount pos = start - b->start;
sampleCount newLen = b->f->GetLength() - len;
samplePtr buffer = NewSamples(newLen, mSampleFormat);
Read(buffer, mSampleFormat, b, 0, pos);
Read(buffer + (pos * sampleSize), mSampleFormat,
b, pos + len, newLen - pos);
SeqBlock *newBlock = new SeqBlock();
newBlock->start = b->start;
newBlock->f =
mDirManager->NewSimpleBlockFile(buffer, newLen, mSampleFormat);
mBlock->Item(b0) = newBlock;
for (unsigned int j = b0 + 1; j < numBlocks; j++)
mBlock->Item(j)->start -= len;
DeleteSamples(buffer);
mDirManager->Deref(b->f);
delete b;
mNumSamples -= len;
UnlockDeleteUpdateMutex();
return ConsistencyCheck(wxT("Delete - branch one"));
}
// Create a new array of blocks
BlockArray *newBlock = new BlockArray();
newBlock->Alloc(numBlocks - (b1 - b0) + 2);
// Copy the blocks before the deletion point over to
// the new array
unsigned int i;
for (i = 0; i < b0; i++) {
newBlock->Add(mBlock->Item(i));
newNumBlocks++;
}
// First grab the samples in block b0 before the deletion point
// into preBuffer. If this is enough samples for its own block,
// or if this would be the first block in the array, write it out.
// Otherwise combine it with the previous block (splitting them
// 50/50 if necessary).
SeqBlock *preBlock = mBlock->Item(b0);
sampleCount preBufferLen = start - preBlock->start;
if (preBufferLen) {
if (preBufferLen >= mMinSamples || b0 == 0) {
SeqBlock *insBlock = new SeqBlock();
insBlock->start = preBlock->start;
samplePtr preBuffer = NewSamples(preBufferLen, mSampleFormat);
Read(preBuffer, mSampleFormat, preBlock, 0, preBufferLen);
insBlock->f =
mDirManager->NewSimpleBlockFile(preBuffer, preBufferLen, mSampleFormat);
DeleteSamples(preBuffer);
newBlock->Add(insBlock);
newNumBlocks++;
if (b0 != b1) {
mDirManager->Deref(preBlock->f);
delete preBlock;
}
} else {
SeqBlock *prepreBlock = mBlock->Item(b0 - 1);
sampleCount prepreLen = prepreBlock->f->GetLength();
sampleCount sum = prepreLen + preBufferLen;
//.........这里部分代码省略.........
示例6: NewSamples
// Pass NULL to set silence
bool Sequence::Set(samplePtr buffer, sampleFormat format,
sampleCount start, sampleCount len)
{
if (start < 0 || start > mNumSamples ||
start+len > mNumSamples)
return false;
samplePtr temp = NULL;
if (format != mSampleFormat) {
temp = NewSamples(mMaxSamples, mSampleFormat);
wxASSERT(temp);
}
samplePtr silence = NULL;
if (!buffer) {
silence = NewSamples(mMaxSamples, format);
wxASSERT(silence);
ClearSamples(silence, format, 0, mMaxSamples);
}
int b = FindBlock(start);
while (len) {
int blen = mBlock->Item(b)->start + mBlock->Item(b)->f->GetLength() - start;
if (blen > len)
blen = len;
if (buffer) {
if (format == mSampleFormat)
CopyWrite(buffer, mBlock->Item(b), start - mBlock->Item(b)->start,
blen);
else {
CopySamples(buffer, format, temp, mSampleFormat, blen);
CopyWrite(temp, mBlock->Item(b), start - mBlock->Item(b)->start,
blen);
}
buffer += (blen * SAMPLE_SIZE(format));
}
else {
// If it's a full block of silence
if (start == mBlock->Item(b)->start &&
blen == mBlock->Item(b)->f->GetLength()) {
mDirManager->Deref(mBlock->Item(b)->f);
mBlock->Item(b)->f = new SilentBlockFile(blen);
}
else {
// Otherwise write silence just to the portion of the block
CopyWrite(silence, mBlock->Item(b),
start - mBlock->Item(b)->start, blen);
}
}
len -= blen;
start += blen;
b++;
}
if (!buffer)
DeleteSamples(silence);
if (format != mSampleFormat)
DeleteSamples(temp);
return ConsistencyCheck(wxT("Set"));
}
示例7: FillDataFromCache
//.........这里部分代码省略.........
bool firstpass = true;
//we decode up to the end of the blockfile
while (len>0 && (mCurrentPos < start+len) && (sc = ReadNextFrame()) != NULL)
{
// ReadNextFrame returns 1 if stream is not to be imported
if (sc != (streamContext*)1)
{
//find out the dts we've seekd to. can't use the stream->cur_dts because it is faulty. also note that until we do the first seek, pkt.dts can be false and will change for the same samples after the initial seek.
sampleCount actualDecodeStart = mCurrentPos;
// we need adjacent samples, so don't use dts most of the time which will leave gaps between frames
// for some formats
// The only other case for inserting silence is for initial offset and ImportFFmpeg.cpp does this for us
if (seeking) {
actualDecodeStart = 0.52 + (sc->m_stream->codec->sample_rate * sc->m_pkt.dts
* ((double)sc->m_stream->time_base.num / sc->m_stream->time_base.den));
//this is mostly safe because den is usually 1 or low number but check for high values.
//hack to get rounding to work to neareset frame size since dts isn't exact
if (sc->m_stream->codec->frame_size) {
actualDecodeStart = ((actualDecodeStart + sc->m_stream->codec->frame_size/2) / sc->m_stream->codec->frame_size) * sc->m_stream->codec->frame_size;
}
// reset for the next one
seeking = false;
}
if(actualDecodeStart != mCurrentPos)
printf("ts not matching - now:%llu , last:%llu, lastlen:%llu, start %llu, len %llu\n",actualDecodeStart, mCurrentPos, mCurrentLen, start, len);
//if we've skipped over some samples, fill the gap with silence. This could happen often in the beginning of the file.
if(actualDecodeStart>start && firstpass) {
// find the number of samples for the leading silence
int amt = actualDecodeStart - start;
FFMpegDecodeCache* cache = new FFMpegDecodeCache;
//printf("skipping/zeroing %i samples. - now:%llu (%f), last:%llu, lastlen:%llu, start %llu, len %llu\n",amt,actualDecodeStart, actualDecodeStartdouble, mCurrentPos, mCurrentLen, start, len);
//put it in the cache so the other channels can use it.
cache->numChannels = sc->m_stream->codec->channels;
cache->len = amt;
cache->start=start;
// 8 bit and 16 bit audio output from ffmpeg means
// 16 bit int out.
// 32 bit int, float, double mean float out.
if (format == int16Sample)
cache->samplefmt = SAMPLE_FMT_S16;
else
cache->samplefmt = SAMPLE_FMT_FLT;
cache->samplePtr = (uint8_t*) malloc(amt * cache->numChannels * SAMPLE_SIZE(format));
memset(cache->samplePtr, 0, amt * cache->numChannels * SAMPLE_SIZE(format));
InsertCache(cache);
}
firstpass=false;
mCurrentPos = actualDecodeStart;
//decode the entire packet (unused bits get saved in cache, so as long as cache size limit is bigger than the
//largest packet size, we're ok.
while (sc->m_pktRemainingSiz > 0)
//Fill the cache with decoded samples
if (DecodeFrame(sc,false) < 0)
break;
// Cleanup after frame decoding
if (sc->m_pktValid)
{
av_free_packet(&sc->m_pkt);
sc->m_pktValid = 0;
}
}
}
// Flush the decoders if we're done.
if((!sc || sc == (streamContext*) 1)&& len>0)
{
for (int i = 0; i < mNumStreams; i++)
{
if (DecodeFrame(mScs[i], true) == 0)
{
if (mScs[i]->m_pktValid)
{
av_free_packet(&mScs[i]->m_pkt);
mScs[i]->m_pktValid = 0;
}
}
}
}
//this next call takes data, start and len as reference variables and updates them to reflect the NEW area that is needed.
FillDataFromCache(bufStart, format, start, len, channel);
// CHECK: not sure if we need this. In any case it has to be updated for the NEW float case (not just int16)
//if for some reason we couldn't get the samples, fill them with silence
/*
int16_t* outBuf = (int16_t*) bufStart;
for(int i=0;i<len;i++)
outBuf[i]=0;
*/
return 1;
}
示例8: int
void Mixer::MixDiffRates(int *channelFlags, WaveTrack * src,
double t0, double t1)
{
if ((t0 - src->GetOffset()) >= src->GetNumSamples() / src->GetRate() ||
(t1 - src->GetOffset()) <= 0)
return;
int s0 = int ((t0 - src->GetOffset()) * src->GetRate());
// get a couple more samples than we need
int slen = int ((t1 - t0) * src->GetRate()) + 2;
int destlen = int ((t1 - t0) * mRate + 0.5);
GetSamples(src, s0, slen);
double volume;
if (mUseVolumeSlider)
volume = mControlToolBar->GetSoundVol();
else
volume = 1.0;
Envelope *e = src->GetEnvelope();
e->GetValues(mEnvValues, mBufferSize, t0, 1.0 / mRate);
// Mix it down to the appropriate tracks
for (int c = 0; c < mNumChannels; c++) {
if (!channelFlags[c])
continue;
samplePtr destPtr;
int skip;
if (mInterleaved) {
destPtr = mBuffer[0] + c*SAMPLE_SIZE(mFormat);
skip = mNumChannels;
} else {
destPtr = mBuffer[c];
skip = 1;
}
// This is the mixing inner loop, which we want
// as optimized as possible
int i = 0;
switch(mFormat) {
case int16Sample: {
short *temp = (short *)mTemp;
short *dest = (short *)destPtr;
int frac = int(32768.0 * (t0 - s0/src->GetRate()));
int fracstep = int(32768.0 * src->GetRate()/mRate + 0.5);
for (int j = 0; j < destlen; j++) {
short value = (temp[i]*(32768-frac) + temp[i+1]*frac) >> 15;
frac += fracstep;
i += (frac >> 15); // frac/32768
frac = (frac & 0x7FFF); // frac%32768
*dest += short(value * volume * mEnvValues[j] + 0.5);
dest += skip;
}
} break;
case int24Sample: {
int *temp = (int *)mTemp;
int *dest = (int *)destPtr;
float frac = t0 - s0/src->GetRate();
float fracstep = src->GetRate()/mRate;
for (int j = 0; j < destlen; j++) {
float value = (temp[i]*(1.0-frac) + temp[i+1]*frac);
frac += fracstep;
int integerPart = (int)frac;
i += integerPart;
frac -= (float)integerPart;
*dest += int(value * volume * mEnvValues[j] + 0.5);
dest += skip;
}
} break;
case floatSample: {
float *temp = (float *)mTemp;
float *dest = (float *)destPtr;
float frac = t0 - s0/src->GetRate();
float fracstep = src->GetRate()/mRate;
for (int j = 0; j < destlen; j++) {
float value = temp[i]*(1.0-frac) + temp[i+1]*frac;
frac += fracstep;
int integerPart = (int)frac;
i += integerPart;
frac -= (float)integerPart;
*dest += value * volume * mEnvValues[j];
dest += skip;
}
} break;
} // switch
//.........这里部分代码省略.........
示例9: file
bool SimpleBlockFile::WriteSimpleBlockFile(
samplePtr sampleData,
sampleCount sampleLen,
sampleFormat format,
void* summaryData)
{
wxFFile file(mFileName.GetFullPath(), wxT("wb"));
if( !file.IsOpened() ){
// Can't do anything else.
return false;
}
auHeader header;
// AU files can be either big or little endian. Which it is is
// determined implicitly by the byte-order of the magic 0x2e736e64
// (.snd). We want it to be native-endian, so we write the magic
// to memory and then let it write that to a file in native
// endianness
header.magic = 0x2e736e64;
// We store the summary data at the end of the header, so the data
// offset is the length of the summary data plus the length of the header
header.dataOffset = sizeof(auHeader) + mSummaryInfo.totalSummaryBytes;
// dataSize is optional, and we opt out
header.dataSize = 0xffffffff;
switch(format) {
case int16Sample:
header.encoding = AU_SAMPLE_FORMAT_16;
break;
case int24Sample:
header.encoding = AU_SAMPLE_FORMAT_24;
break;
case floatSample:
header.encoding = AU_SAMPLE_FORMAT_FLOAT;
break;
}
// TODO: don't fabricate
header.sampleRate = 44100;
// BlockFiles are always mono
header.channels = 1;
// Write the file
ArrayOf<char> cleanup;
if (!summaryData)
summaryData = /*BlockFile::*/CalcSummary(sampleData, sampleLen, format, cleanup);
//mchinen:allowing virtual override of calc summary for ODDecodeBlockFile.
// PRL: cleanup fixes a possible memory leak!
size_t nBytesToWrite = sizeof(header);
size_t nBytesWritten = file.Write(&header, nBytesToWrite);
if (nBytesWritten != nBytesToWrite)
{
wxLogDebug(wxT("Wrote %lld bytes, expected %lld."), (long long) nBytesWritten, (long long) nBytesToWrite);
return false;
}
nBytesToWrite = mSummaryInfo.totalSummaryBytes;
nBytesWritten = file.Write(summaryData, nBytesToWrite);
if (nBytesWritten != nBytesToWrite)
{
wxLogDebug(wxT("Wrote %lld bytes, expected %lld."), (long long) nBytesWritten, (long long) nBytesToWrite);
return false;
}
if( format == int24Sample )
{
// we can't write the buffer directly to disk, because 24-bit samples
// on disk need to be packed, not padded to 32 bits like they are in
// memory
int *int24sampleData = (int*)sampleData;
for( int i = 0; i < sampleLen; i++ )
{
nBytesToWrite = 3;
nBytesWritten =
#if wxBYTE_ORDER == wxBIG_ENDIAN
file.Write((char*)&int24sampleData[i] + 1, nBytesToWrite);
#else
file.Write((char*)&int24sampleData[i], nBytesToWrite);
#endif
if (nBytesWritten != nBytesToWrite)
{
wxLogDebug(wxT("Wrote %lld bytes, expected %lld."), (long long) nBytesWritten, (long long) nBytesToWrite);
return false;
}
}
}
else
{
// for all other sample formats we can write straight from the buffer
// to disk
nBytesToWrite = sampleLen * SAMPLE_SIZE(format);
nBytesWritten = file.Write(sampleData, nBytesToWrite);
//.........这里部分代码省略.........
示例10: SAMPLE_SIZE
sampleCount Mixer::MixVariableRates(int *channelFlags, WaveTrack *track,
longSampleCount *pos, float *queue,
int *queueStart, int *queueLen,
Resample *SRC)
{
double initialWarp = mRate / track->GetRate();
double t = *pos / track->GetRate();
int sampleSize = SAMPLE_SIZE(floatSample);
int i, c;
sampleCount out = 0;
while(out < mMaxOut) {
if (*queueLen < mProcessLen) {
memmove(queue, &queue[*queueStart],
(*queueLen)*sampleSize);
*queueStart = 0;
int getLen = mQueueMaxLen - *queueLen;
#if 0
// TODO: fix this code so that extra silence isn't added
// to the end of a track
double trackTime = (*pos + getLen) / track->GetRate();
if (trackTime > track->GetEndTime()) {
getLen = (int)(0.5 + track->GetRate() *
(track->GetEndTime() -
((*pos) / track->GetRate())));
}
#endif
track->Get((samplePtr)&queue[*queueLen], floatSample,
*pos, getLen);
track->GetEnvelopeValues(mEnvValues, getLen, (*pos) / track->GetRate(),
1.0 / track->GetRate());
for(i=0; i<getLen; i++)
queue[(*queueLen)+i] *= mEnvValues[i];
*queueLen += getLen;
*pos += getLen;
}
sampleCount thisProcessLen = mProcessLen;
if (*queueLen < mProcessLen)
thisProcessLen = *queueLen;
double factor = initialWarp;
if (mTimeTrack) {
double warpFactor = mTimeTrack->GetEnvelope()->GetValue(t);
warpFactor = (mTimeTrack->GetRangeLower() * (1 - warpFactor) +
warpFactor * mTimeTrack->GetRangeUpper())/100.0;
factor /= warpFactor;
}
int input_used;
bool last = (*queueLen < mProcessLen);
int outgen = SRC->Process(factor,
&queue[*queueStart],
thisProcessLen,
last,
&input_used,
&mFloatBuffer[out],
mMaxOut - out);
if (outgen < 0)
return 0;
*queueStart += input_used;
*queueLen -= input_used;
out += outgen;
t += (input_used / track->GetRate());
if (last)
break;
}
for(c=0; c<mNumChannels; c++)
if (mApplyTrackGains)
mGains[c] = track->GetChannelGain(c);
else
mGains[c] = 1.0;
MixBuffers(mNumChannels, channelFlags, mGains,
(samplePtr)mFloatBuffer, mTemp, mMaxOut, mInterleaved);
return mMaxOut;
}
示例11: memset
void Mixer::Clear()
{
for (int c = 0; c < mNumBuffers; c++) {
memset(mTemp[c], 0, mInterleavedBufferSize * SAMPLE_SIZE(floatSample));
}
}
示例12: sf_open
int BlockFile::ReadData(void *data, sampleFormat format,
sampleCount start, sampleCount len)
{
int i;
if (mType == BLOCK_TYPE_ALIAS) {
SF_INFO info;
SNDFILE *sf = sf_open(mAliasFullPath, SFM_READ, &info);
if (!sf)
return 0;
sf_seek(sf, mStart + start, SEEK_SET);
samplePtr buffer = NewSamples(len * info.channels, floatSample);
int framesRead = 0;
switch(format) {
case int16Sample:
framesRead = sf_readf_short(sf, (short *)buffer, len);
for (i = 0; i < framesRead; i++)
((short *)data)[i] =
((short *)buffer)[(info.channels * i) + mChannel];
break;
case floatSample:
framesRead = sf_readf_float(sf, (float *)buffer, len);
for (i = 0; i < framesRead; i++)
((float *)data)[i] =
((float *)buffer)[(info.channels * i) + mChannel];
break;
default:
framesRead = sf_readf_float(sf, (float *)buffer, len);
for (i = 0; i < framesRead; i++)
((float *)buffer)[i] =
((float *)buffer)[(info.channels * i) + mChannel];
CopySamples((samplePtr)buffer, floatSample,
(samplePtr)data, format, framesRead);
}
DeleteSamples(buffer);
sf_close(sf);
return framesRead;
}
else {
wxFFile file;
int read;
if (!file.Open((const wxChar *) mFullPath, "rb"))
return 0;
file.Seek(mSummaryLen +
start * SAMPLE_SIZE(mSampleFormat), wxFromStart);
if (format == mSampleFormat) {
int bytes = len * SAMPLE_SIZE(mSampleFormat);
read = (int)file.Read(data, (size_t)bytes);
read /= SAMPLE_SIZE(mSampleFormat);
}
else {
samplePtr buffer = NewSamples(len, mSampleFormat);
int srcBytes = len * SAMPLE_SIZE(mSampleFormat);
read = (int)file.Read(buffer, (size_t)srcBytes);
read /= SAMPLE_SIZE(mSampleFormat);
CopySamples(buffer, mSampleFormat,
(samplePtr)data, format, read);
DeleteSamples(buffer);
}
file.Close();
return read;
}
}
示例13: SAMPLE_SIZE
sampleCount Mixer::MixVariableRates(int *channelFlags, WaveTrack *track,
longSampleCount *pos, float *queue,
int *queueStart, int *queueLen,
Resample *SRC)
{
double trackRate = track->GetRate();
double initialWarp = mRate / trackRate;
double t = *pos / trackRate;
int sampleSize = SAMPLE_SIZE(floatSample);
int i, c;
sampleCount out = 0;
// Find the last sample
longSampleCount last = -1;
WaveClipList::Node* it = track->GetClipIterator();
while (it) {
longSampleCount end = it->GetData()->GetEndSample();
if (end > last) {
last = end;
}
it = it->GetNext();
}
longSampleCount max = trackRate * mT1;
if (last > max)
last = max;
while(out < mMaxOut) {
if (*queueLen < mProcessLen) {
memmove(queue, &queue[*queueStart], (*queueLen)*sampleSize);
*queueStart = 0;
int getLen = mQueueMaxLen - *queueLen;
// Constrain
if (*pos + getLen > last) {
getLen = last - *pos;
}
// Nothing to do if past end of track
if (getLen <= 0) {
break;
}
track->Get((samplePtr)&queue[*queueLen], floatSample,
*pos, getLen);
track->GetEnvelopeValues(mEnvValues, getLen, (*pos) / trackRate,
1.0 / trackRate);
for(i=0; i<getLen; i++)
queue[(*queueLen)+i] *= mEnvValues[i];
*queueLen += getLen;
*pos += getLen;
}
sampleCount thisProcessLen = mProcessLen;
if (*queueLen < mProcessLen)
thisProcessLen = *queueLen;
double factor = initialWarp;
if (mTimeTrack) {
double warpFactor = mTimeTrack->GetEnvelope()->GetValue(t);
warpFactor = (mTimeTrack->GetRangeLower() * (1 - warpFactor) +
warpFactor * mTimeTrack->GetRangeUpper())/100.0;
factor /= warpFactor;
}
int input_used;
bool last = (*queueLen < mProcessLen);
int outgen = SRC->Process(factor,
&queue[*queueStart],
thisProcessLen,
last,
&input_used,
&mFloatBuffer[out],
mMaxOut - out);
if (outgen < 0)
return 0;
*queueStart += input_used;
*queueLen -= input_used;
out += outgen;
t += (input_used / trackRate);
if (last)
break;
}
for(c=0; c<mNumChannels; c++)
if (mApplyTrackGains)
mGains[c] = track->GetChannelGain(c);
else
mGains[c] = 1.0;
MixBuffers(mNumChannels, channelFlags, mGains,
(samplePtr)mFloatBuffer, mTemp, out, mInterleaved);
//.........这里部分代码省略.........
示例14: RemoveDependencies
// Given a project and a list of aliased files that should no
// longer be external dependencies (selected by the user), replace
// all of those alias block files with disk block files.
void RemoveDependencies(AudacityProject *project,
AliasedFileArray *aliasedFiles)
{
DirManager *dirManager = project->GetDirManager();
ProgressDialog *progress =
new ProgressDialog(_("Removing Dependencies"),
_("Copying audio data into project..."));
int updateResult = eProgressSuccess;
// Hash aliasedFiles based on their full paths and
// count total number of bytes to process.
AliasedFileHash aliasedFileHash;
wxLongLong totalBytesToProcess = 0;
unsigned int i;
for (i = 0; i < aliasedFiles->GetCount(); i++) {
totalBytesToProcess += aliasedFiles->Item(i).mByteCount;
wxString fileNameStr = aliasedFiles->Item(i).mFileName.GetFullPath();
aliasedFileHash[fileNameStr] = &aliasedFiles->Item(i);
}
BlockArray blocks;
GetAllSeqBlocks(project, &blocks);
const sampleFormat format = project->GetDefaultFormat();
ReplacedBlockFileHash blockFileHash;
wxLongLong completedBytes = 0;
for (i = 0; i < blocks.GetCount(); i++) {
BlockFile *f = blocks[i]->f;
if (f->IsAlias() && (blockFileHash.count(f) == 0))
{
// f is an alias block we have not yet processed.
AliasBlockFile *aliasBlockFile = (AliasBlockFile *)f;
wxFileName fileName = aliasBlockFile->GetAliasedFileName();
wxString fileNameStr = fileName.GetFullPath();
if (aliasedFileHash.count(fileNameStr) == 0)
// This aliased file was not selected to be replaced. Skip it.
continue;
// Convert it from an aliased file to an actual file in the project.
unsigned int len = aliasBlockFile->GetLength();
samplePtr buffer = NewSamples(len, format);
f->ReadData(buffer, format, 0, len);
BlockFile *newBlockFile =
dirManager->NewSimpleBlockFile(buffer, len, format);
DeleteSamples(buffer);
// Update our hash so we know what block files we've done
blockFileHash[f] = newBlockFile;
// Update the progress bar
completedBytes += SAMPLE_SIZE(format) * len;
updateResult = progress->Update(completedBytes, totalBytesToProcess);
if (updateResult != eProgressSuccess)
break;
}
}
// Above, we created a SimpleBlockFile contained in our project
// to go with each AliasBlockFile that we wanted to migrate.
// However, that didn't actually change any references to these
// blockfiles in the Sequences, so we do that next...
ReplaceBlockFiles(project, blockFileHash);
// Subtract one from reference count of new block files; they're
// now all referenced the proper number of times by the Sequences
ReplacedBlockFileHash::iterator it;
for( it = blockFileHash.begin(); it != blockFileHash.end(); ++it )
{
BlockFile *f = it->second;
dirManager->Deref(f);
}
delete progress;
}
示例15: ComputeLegacySummaryInfo
void ComputeLegacySummaryInfo(wxFileName fileName,
int summaryLen,
sampleFormat format,
SummaryInfo *info,
bool noRMS,
float *min, float *max, float *rms)
{
int fields = 3; /* min, max, rms */
if (noRMS)
fields = 2;
info->fields = fields;
info->format = format;
info->bytesPerFrame =
SAMPLE_SIZE(info->format) * fields;
info->totalSummaryBytes = summaryLen;
info->offset64K = 20; /* legacy header tag len */
info->frames64K = (summaryLen-20) /
(info->bytesPerFrame * 256);
info->offset256 = info->offset64K +
(info->frames64K * info->bytesPerFrame);
info->frames256 =
(summaryLen - 20 -
(info->frames64K * info->bytesPerFrame)) /
info->bytesPerFrame;
//
// Compute the min, max, and RMS of the block from the
// 64K summary data
//
float *summary = new float[info->frames64K * fields];
samplePtr data = NewSamples(info->frames64K * fields,
info->format);
wxFFile summaryFile;
if( !summaryFile.Open(fileName.GetFullPath(), "rb") ) {
delete[] data;
return;
}
summaryFile.Seek(info->offset64K);
int read = summaryFile.Read(data,
info->frames64K *
info->bytesPerFrame);
int count = read / info->bytesPerFrame;
CopySamples(data, info->format,
(samplePtr)summary, floatSample, count);
(*min) = FLT_MAX;
(*max) = FLT_MIN;
float sumsq = 0;
for(int i=0; i<count; i++) {
if (summary[fields*i] < (*min))
(*min) = summary[fields*i];
if (summary[fields*i+1] > (*max))
(*max) = summary[fields*i+1];
if (fields >= 3)
sumsq += summary[fields*i+2]*summary[fields*i+2];
}
if (fields >= 3)
(*rms) = sqrt(sumsq / count);
else
(*rms) = 0;
DeleteSamples(data);
delete[] summary;
}