本文整理汇总了C++中WaveTrack::GetSampleFormat方法的典型用法代码示例。如果您正苦于以下问题:C++ WaveTrack::GetSampleFormat方法的具体用法?C++ WaveTrack::GetSampleFormat怎么用?C++ WaveTrack::GetSampleFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WaveTrack
的用法示例。
在下文中一共展示了WaveTrack::GetSampleFormat方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Process
bool EffectNoise::Process()
{
if (noiseDuration <= 0.0)
noiseDuration = sDefaultGenerateLen;
//Iterate over each track
TrackListIterator iter(mWaveTracks);
WaveTrack *track = (WaveTrack *)iter.First();
while (track) {
WaveTrack *tmp = mFactory->NewWaveTrack(track->GetSampleFormat(), track->GetRate());
numSamples = (longSampleCount)(noiseDuration * track->GetRate() + 0.5);
longSampleCount i = 0;
float *data = new float[tmp->GetMaxBlockSize()];
sampleCount block;
while(i < numSamples) {
block = tmp->GetBestBlockSize(i);
if (block > (numSamples - i))
block = numSamples - i;
MakeNoise(data, block, track->GetRate(), noiseAmplitude);
tmp->Append((samplePtr)data, floatSample, block);
i += block;
}
delete[] data;
tmp->Flush();
track->Clear(mT0, mT1);
track->Paste(mT0, tmp);
delete tmp;
//Iterate to the next track
track = (WaveTrack *)iter.Next();
}
/*
save last used values
save duration unless value was got from selection, so we save only
when user explicitely setup a value
*/
if (mT1 == mT0)
gPrefs->Write(wxT("/CsPresets/NoiseGen_Duration"), noiseDuration);
gPrefs->Write(wxT("/CsPresets/NoiseGen_Type"), noiseType);
gPrefs->Write(wxT("/CsPresets/NoiseGen_Amp"), noiseAmplitude);
mT1 = mT0 + noiseDuration; // Update selection.
return true;
}
示例2: Process
bool EffectToneGen::Process()
{
if (length <= 0.0)
length = sDefaultGenerateLen;
//Iterate over each track
TrackListIterator iter(mWaveTracks);
WaveTrack *track = (WaveTrack *)iter.First();
while (track) {
mSample = 0;
WaveTrack *tmp = mFactory->NewWaveTrack(track->GetSampleFormat());
mCurRate = track->GetRate();
tmp->SetRate(mCurRate);
longSampleCount numSamples =
(longSampleCount)(length * mCurRate + 0.5);
longSampleCount i = 0;
float *data = new float[tmp->GetMaxBlockSize()];
sampleCount block;
while(i < numSamples) {
block = tmp->GetBestBlockSize(i);
if (block > (numSamples - i))
block = numSamples - i;
MakeTone(data, block);
tmp->Append((samplePtr)data, floatSample, block);
i += block;
}
delete[] data;
tmp->Flush();
track->Clear(mT0, mT1);
track->Paste(mT0, tmp);
delete tmp;
//Iterate to the next track
track = (WaveTrack *)iter.Next();
}
mT1 = mT0 + length; // Update selection.
return true;
}
示例3: Process
bool EffectSilence::Process()
{
if (length <= 0.0)
length = sDefaultGenerateLen;
TrackListIterator iter(mWaveTracks);
WaveTrack *track = (WaveTrack *)iter.First();
while (track) {
WaveTrack *tmp = mFactory->NewWaveTrack(track->GetSampleFormat(), track->GetRate());
tmp->InsertSilence(0.0, length);
tmp->Flush();
track->Clear(mT0, mT1);
track->Paste(mT0, tmp);
delete tmp;
//Iterate to the next track
track = (WaveTrack *)iter.Next();
}
mT1 = mT0 + length; // Update selection.
return true;
}
示例4: Process
bool Generator::Process()
{
if (GetDuration() < 0.0)
return false;
// Set up mOutputTracks.
// This effect needs Track::All for sync-lock grouping.
this->CopyInputTracks(Track::All);
// Iterate over the tracks
bool bGoodResult = true;
int ntrack = 0;
TrackListIterator iter(mOutputTracks);
Track* t = iter.First();
while (t != NULL)
{
if (t->GetKind() == Track::Wave && t->GetSelected()) {
WaveTrack* track = (WaveTrack*)t;
bool editClipCanMove;
gPrefs->Read(wxT("/GUI/EditClipCanMove"), &editClipCanMove, true);
//if we can't move clips, and we're generating into an empty space,
//make sure there's room.
if (!editClipCanMove &&
track->IsEmpty(mT0, mT1+1.0/track->GetRate()) &&
!track->IsEmpty(mT0, mT0+GetDuration()-(mT1-mT0)-1.0/track->GetRate()))
{
wxMessageBox(
_("There is not enough room available to generate the audio"),
_("Error"), wxICON_STOP);
Failure();
return false;
}
if (GetDuration() > 0.0)
{
AudacityProject *p = GetActiveProject();
// Create a temporary track
std::unique_ptr<WaveTrack> tmp(
mFactory->NewWaveTrack(track->GetSampleFormat(),
track->GetRate())
);
BeforeTrack(*track);
BeforeGenerate();
// Fill it with data
if (!GenerateTrack(&*tmp, *track, ntrack))
bGoodResult = false;
else {
// Transfer the data from the temporary track to the actual one
tmp->Flush();
SetTimeWarper(new StepTimeWarper(mT0+GetDuration(), GetDuration()-(mT1-mT0)));
bGoodResult = track->ClearAndPaste(p->GetSel0(), p->GetSel1(), &*tmp, true,
false, GetTimeWarper());
}
if (!bGoodResult) {
Failure();
return false;
}
}
else
{
// If the duration is zero, there's no need to actually
// generate anything
track->Clear(mT0, mT1);
}
ntrack++;
}
else if (t->IsSyncLockSelected()) {
t->SyncLockAdjust(mT1, mT0 + GetDuration());
}
// Move on to the next track
t = iter.Next();
}
Success();
this->ReplaceProcessedTracks(bGoodResult);
mT1 = mT0 + GetDuration(); // Update selection.
return true;
}
示例5: Process
//------------------------- Processing methods -------------------------
bool EffectSineSweepGenerator::Process()
{
// taken `as is` from Audacity`s Generator.cpp to resolve
// a vc++ linking problem...
if (mDuration < 0.0)
return false;
BeforeGenerate();
// Set up mOutputTracks. This effect needs Track::All for grouping
this->CopyInputTracks(Track::All);
// Iterate over the tracks
bool bGoodResult = true;
int ntrack = 0;
TrackListIterator iter(mOutputTracks);
Track* t = iter.First();
while (t != NULL)
{
if (t->GetKind() == Track::Wave && t->GetSelected())
{
WaveTrack* track = (WaveTrack*)t;
bool editClipCanMove = true;
//gPrefs->Read(wxT("/GUI/EditClipCanMove"), &editClipCanMove, true);
//if we can't move clips, and we're generating into an empty space,
//make sure there's room.
if (!editClipCanMove &&
track->IsEmpty(mT0, mT1+1.0/track->GetRate()) &&
!track->IsEmpty(mT0, mT0+mDuration-(mT1-mT0)-1.0/track->GetRate()))
{
wxMessageBox(_("There is not enough room available to generate the audio"),
_("Error"), wxICON_STOP);
Failure();
return false;
}
if (mDuration > 0.0)
{
// Create a temporary track
WaveTrack *tmp = mFactory->NewWaveTrack(track->GetSampleFormat(),
track->GetRate());
//BeforeTrack(*track);
// Fill it with data
if (!GenerateTrack(tmp, *track, ntrack))
bGoodResult = false;
else
{
// Transfer the data from the temporary track to the actual one
tmp->Flush();
SetTimeWarper(new AFStepTimeWarper(mT0+mDuration, mDuration-(mT1-mT0)));
bGoodResult = track->ClearAndPaste(mT0, mT1, tmp, true,
false, GetTimeWarper());
delete tmp;
}
if (!bGoodResult)
{
Failure();
return false;
}
}
else
{
// If the duration is zero, there's no need to actually
// generate anything
track->Clear(mT0, mT1);
}
ntrack++;
}
else if (t->IsSyncLockSelected())
{
t->SyncLockAdjust(mT1, mT0 + mDuration);
}
// Move on to the next track
t = iter.Next();
}
Success();
this->ReplaceProcessedTracks(bGoodResult);
mT1 = mT0 + mDuration; // Update selection.
return true;
}
示例6: Process
bool EffectNoise::Process()
{
if (noiseDuration <= 0.0)
noiseDuration = sDefaultGenerateLen;
//Iterate over each track
int ntrack = 0;
this->CopyInputWaveTracks(); // Set up mOutputWaveTracks.
bool bGoodResult = true;
TrackListIterator iter(mOutputWaveTracks);
WaveTrack *track = (WaveTrack *)iter.First();
while (track) {
WaveTrack *tmp = mFactory->NewWaveTrack(track->GetSampleFormat(), track->GetRate());
numSamples = (longSampleCount)(noiseDuration * track->GetRate() + 0.5);
longSampleCount i = 0;
float *data = new float[tmp->GetMaxBlockSize()];
sampleCount block;
while ((i < numSamples) && bGoodResult) {
block = tmp->GetBestBlockSize(i);
if (block > (numSamples - i))
block = numSamples - i;
MakeNoise(data, block, track->GetRate(), noiseAmplitude);
tmp->Append((samplePtr)data, floatSample, block);
i += block;
//Update the Progress meter
if (TrackProgress(ntrack, (double)i / numSamples))
bGoodResult = false;
}
delete[] data;
tmp->Flush();
track->Clear(mT0, mT1);
track->Paste(mT0, tmp);
delete tmp;
if (!bGoodResult)
break;
//Iterate to the next track
ntrack++;
track = (WaveTrack *)iter.Next();
}
if (bGoodResult)
{
/*
save last used values
save duration unless value was got from selection, so we save only
when user explicitely setup a value
*/
if (mT1 == mT0)
gPrefs->Write(wxT("/CsPresets/NoiseGen_Duration"), noiseDuration);
gPrefs->Write(wxT("/CsPresets/NoiseGen_Type"), noiseType);
gPrefs->Write(wxT("/CsPresets/NoiseGen_Amp"), noiseAmplitude);
mT1 = mT0 + noiseDuration; // Update selection.
}
this->ReplaceProcessedWaveTracks(bGoodResult);
return bGoodResult;
}
示例7: Process
//.........这里部分代码省略.........
(long)((float)(start-trackStart)*(srProcess/srTrack)));
trackPresamples = wxMin(start-trackStart,
(long)((float)(processPresamples)*(srTrack/srProcess)));
rb.offset = start - trackPresamples;
rb.end = trackEnd;
rb.iface = new SBSMSEffectInterface(rb.resampler,
&rateSlide,&pitchSlide,
bPitchReferenceInput,
samplesToProcess,processPresamples,
rb.quality);
}
Resampler resampler(outResampleCB,&rb,outSlideType);
audio outBuf[SBSMSOutBlockSize];
float outBufLeft[2*SBSMSOutBlockSize];
float outBufRight[2*SBSMSOutBlockSize];
// Samples in output after SBSMS
sampleCount samplesToOutput = rb.iface->getSamplesToOutput();
// Samples in output after resampling back
sampleCount samplesOut = (sampleCount) ((float)samplesToOutput * (srTrack/srProcess));
// Duration in track time
double duration = (mCurT1-mCurT0) * mTotalStretch;
if(duration > maxDuration)
maxDuration = duration;
TimeWarper *warper = createTimeWarper(mCurT0,mCurT1,maxDuration,rateStart,rateEnd,rateSlideType);
SetTimeWarper(warper);
rb.outputLeftTrack = mFactory->NewWaveTrack(leftTrack->GetSampleFormat(),
leftTrack->GetRate());
if(rightTrack)
rb.outputRightTrack = mFactory->NewWaveTrack(rightTrack->GetSampleFormat(),
rightTrack->GetRate());
long pos = 0;
long outputCount = -1;
// process
while(pos<samplesOut && outputCount) {
long frames;
if(pos+SBSMSOutBlockSize>samplesOut) {
frames = samplesOut - pos;
} else {
frames = SBSMSOutBlockSize;
}
outputCount = resampler.read(outBuf,frames);
for(int i = 0; i < outputCount; i++) {
outBufLeft[i] = outBuf[i][0];
if(rightTrack)
outBufRight[i] = outBuf[i][1];
}
pos += outputCount;
rb.outputLeftTrack->Append((samplePtr)outBufLeft, floatSample, outputCount);
if(rightTrack)
rb.outputRightTrack->Append((samplePtr)outBufRight, floatSample, outputCount);
double frac = (double)pos/(double)samplesOut;
int nWhichTrack = mCurTrackNum;
if(rightTrack) {
nWhichTrack = 2*(mCurTrackNum/2);
if (frac < 0.5)
frac *= 2.0; // Show twice as far for each track, because we're doing 2 at once.
示例8: Process
//.........这里部分代码省略.........
// Samples in output after resampling back
sampleCount samplesToGenerate = (sampleCount) ((real)samplesToProcess * mTotalStretch);
sampleCount samplesOut = (sampleCount) ((real)samplesIn * mTotalStretch);
double duration = (mCurT1-mCurT0) * mTotalStretch;
if(duration > maxDuration)
maxDuration = duration;
TimeWarper *warper = NULL;
if (rateStart == rateEnd)
{
warper = new LinearTimeWarper(mCurT0, mCurT0,
mCurT1, mCurT0+maxDuration);
} else
{
warper = new LogarithmicTimeWarper(mCurT0, mCurT1,
rateStart, rateEnd);
}
SetTimeWarper(warper);
sbsmsInfo si;
si.rs = rb.resampler;
si.samplesToProcess = samplesToProcess;
si.samplesToGenerate = samplesToGenerate;
si.stretch0 = rateStart;
si.stretch1 = rateEnd;
si.ratio0 = pitchStart;
si.ratio1 = pitchEnd;
rb.sbsmser = sbsms_create(&samplesCB,&stretchCB,&ratioCB,rightTrack?2:1,quality,bPreAnalyze,true);
rb.pitch = pitch_create(rb.sbsmser,&si,srIn/srSBSMS);
rb.outputLeftTrack = mFactory->NewWaveTrack(leftTrack->GetSampleFormat(),
leftTrack->GetRate());
if(rightTrack)
rb.outputRightTrack = mFactory->NewWaveTrack(rightTrack->GetSampleFormat(),
rightTrack->GetRate());
sampleCount blockSize = SBSMS_FRAME_SIZE[quality];
rb.outBuf = (audio*)calloc(blockSize,sizeof(audio));
rb.outputLeftBuffer = (float*)calloc(blockSize*2,sizeof(float));
if(rightTrack)
rb.outputRightBuffer = (float*)calloc(blockSize*2,sizeof(float));
long pos = 0;
long outputCount = -1;
// pre analysis
real fracPre = 0.0f;
if(bPreAnalyze) {
fracPre = 0.05f;
resampleBuf rbPre;
rbPre.block = maxBlockSize;
rbPre.buf = (audio*)calloc(rb.block,sizeof(audio));
rbPre.leftTrack = leftTrack;
rbPre.rightTrack = rightTrack?rightTrack:leftTrack;
rbPre.leftBuffer = (float*)calloc(maxBlockSize,sizeof(float));
rbPre.rightBuffer = (float*)calloc(maxBlockSize,sizeof(float));
rbPre.offset = start;
rbPre.end = end;
rbPre.ratio = srSBSMS/srIn;
rbPre.resampler = new Resampler(resampleCB, &rbPre);
si.rs = rbPre.resampler;
示例9: Process
bool EffectDtmf::Process()
{
if (dtmfDuration <= 0.0)
return false;
//Iterate over each track
TrackListIterator iter(mWaveTracks);
WaveTrack *track = (WaveTrack *)iter.First();
while (track) {
// new tmp track, to fill with dtmf sequence
// we will build the track by adding a tone, then a silence, next tone, and so on...
WaveTrack *tmp = mFactory->NewWaveTrack(track->GetSampleFormat(), track->GetRate());
// all dtmf sequence durations in samples from seconds
numSamplesSequence = (longSampleCount)(dtmfDuration * track->GetRate() + 0.5);
numSamplesTone = (longSampleCount)(dtmfTone * track->GetRate() + 0.5);
numSamplesSilence = (longSampleCount)(dtmfSilence * track->GetRate() + 0.5);
// recalculate the sum, and spread the difference - due to approximations.
// Since diff should be in the order of "some" samples, a division (resulting in zero)
// is not sufficient, so we add the additional remaining samples in each tone/silence block,
// at least until available.
int diff = numSamplesSequence - (dtmfNTones*numSamplesTone) - (dtmfNTones-1)*numSamplesSilence;
if (diff>dtmfNTones) {
// in this case, both these values would change, so it makes sense to recalculate diff
// otherwise just keep the value we already have
// should always be the case that dtmfNTones>1, as if 0, we don't even start processing,
// and with 1 there is no difference to spread (no silence slot)...
wxASSERT(dtmfNTones > 1);
numSamplesTone += (diff/(dtmfNTones));
numSamplesSilence += (diff/(dtmfNTones-1));
diff = numSamplesSequence - (dtmfNTones*numSamplesTone) - (dtmfNTones-1)*numSamplesSilence;
}
// this var will be used as extra samples distributor
int extra=0;
longSampleCount i = 0;
longSampleCount j = 0;
int n=0; // pointer to string in dtmfString
sampleCount block;
bool isTone = true;
float *data = new float[tmp->GetMaxBlockSize()];
// for the whole dtmf sequence, we will be generating either tone or silence
// according to a bool value, and this might be done in small chunks of size
// 'block', as a single tone might sometimes be larger than the block
// tone and silence generally have different duration, thus two generation blocks
//
// Note: to overcome a 'clicking' noise introduced by the abrupt transition from/to
// silence, I added a fade in/out of 1/250th of a second (4ms). This can still be
// tweaked but gives excellent results at 44.1kHz: I haven't tried other freqs.
// A problem might be if the tone duration is very short (<10ms)... (?)
//
// One more problem is to deal with the approximations done when calculating the duration
// of both tone and silence: in some cases the final sum might not be same as the initial
// duration. So, to overcome this, we had a redistribution block up, and now we will spread
// the remaining samples in every bin in order to achieve the full duration: test case was
// to generate an 11 tone DTMF sequence, in 4 seconds, and with DutyCycle=75%: after generation
// you ended up with 3.999s or in other units: 3 seconds and 44097 samples.
//
while(i < numSamplesSequence) {
if (isTone)
// generate tone
{
// the statement takes care of extracting one sample from the diff bin and
// adding it into the tone block until depletion
extra=(diff-- > 0?1:0);
for(j=0; j < numSamplesTone+extra; j+=block) {
block = tmp->GetBestBlockSize(j);
if (block > (numSamplesTone+extra - j))
block = numSamplesTone+extra - j;
// generate the tone and append
MakeDtmfTone(data, block, track->GetRate(), dtmfString[n], j, numSamplesTone);
tmp->Append((samplePtr)data, floatSample, block);
}
i += numSamplesTone;
n++;
if(n>=dtmfNTones)break;
}
else
// generate silence
{
// the statement takes care of extracting one sample from the diff bin and
// adding it into the silence block until depletion
extra=(diff-- > 0?1:0);
for(j=0; j < numSamplesSilence+extra; j+=block) {
block = tmp->GetBestBlockSize(j);
if (block > (numSamplesSilence+extra - j))
block = numSamplesSilence+extra - j;
// generate silence and append
memset(data, 0, sizeof(float)*block);
tmp->Append((samplePtr)data, floatSample, block);
}
i += numSamplesSilence;
}
// flip flag
isTone=!isTone;
//.........这里部分代码省略.........