本文整理汇总了C++中Mixer::MixRight方法的典型用法代码示例。如果您正苦于以下问题:C++ Mixer::MixRight方法的具体用法?C++ Mixer::MixRight怎么用?C++ Mixer::MixRight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mixer
的用法示例。
在下文中一共展示了Mixer::MixRight方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ExportOGG
//.........这里部分代码省略.........
outFile.Write(page.body, page.body_len);
double t = t0;
bool done = false;
wxProgressDialog *progress = NULL;
wxYield();
wxStartTimer();
while(!done && !cancelling){
float deltat = (float)SAMPLES_PER_RUN / rate;
sampleCount samplesThisRun = SAMPLES_PER_RUN;
Mixer *mixer = new Mixer(stereo ? 2 : 1, SAMPLES_PER_RUN,
/* interleaved = */ false, rate, floatSample);
if(t + deltat > t1) {
done = true;
deltat = t1 - t;
samplesThisRun = int(deltat * rate + 0.5);
}
mixer->Clear();
TrackListIterator iter(tracks);
Track *tr = iter.First();
while (tr) {
if (tr->GetKind() == Track::Wave) {
if (tr->GetSelected() || !selectionOnly) {
if (tr->GetChannel() == Track::MonoChannel)
mixer->MixMono((WaveTrack *) tr, t, t + deltat);
else if (tr->GetChannel() == Track::LeftChannel)
mixer->MixLeft((WaveTrack *) tr, t, t + deltat);
else if (tr->GetChannel() == Track::RightChannel)
mixer->MixRight((WaveTrack *) tr, t, t + deltat);
}
}
tr = iter.Next();
}
float **vorbis_buffer = vorbis_analysis_buffer(&dsp, SAMPLES_PER_RUN);
float *left = (float *)mixer->GetBuffer(0);
memcpy(vorbis_buffer[0], left, sizeof(float)*SAMPLES_PER_RUN);
if(stereo) {
float *right = (float *)mixer->GetBuffer(1);
memcpy(vorbis_buffer[1], right, sizeof(float)*SAMPLES_PER_RUN);
}
// tell the encoder how many samples we have
vorbis_analysis_wrote(&dsp, samplesThisRun);
// I don't understand what this call does, so here is the comment
// from the example, verbatim:
//
// vorbis does some data preanalysis, then divvies up blocks
// for more involved (potentially parallel) processing. Get
// a single block for encoding now
while(vorbis_analysis_blockout(&dsp, &block) == 1) {
// analysis, assume we want to use bitrate management
vorbis_analysis(&block, NULL);
vorbis_bitrate_addblock(&block);
while(vorbis_bitrate_flushpacket(&dsp, &packet)) {
示例2: QuickMix
bool QuickMix(TrackList *tracks, DirManager *dirManager,
double rate, sampleFormat format)
{
WaveTrack **waveArray;
VTrack *t;
int numWaves = 0;
int numLeft = 0;
int numRight = 0;
int numMono = 0;
bool mono = false;
int w;
TrackListIterator iter(tracks);
t = iter.First();
while (t) {
if (t->GetSelected() && t->GetKind() == VTrack::Wave) {
numWaves++;
switch (t->GetChannel()) {
case VTrack::MonoChannel:
numLeft++;
numRight++;
numMono++;
break;
case VTrack::LeftChannel:
numLeft++;
break;
case VTrack::RightChannel:
numRight++;
break;
}
}
t = iter.Next();
}
if (numMono == numWaves || numLeft == numWaves || numRight == numWaves)
mono = true;
double totalTime = 0.0;
waveArray = new WaveTrack *[numWaves];
w = 0;
t = iter.First();
while (t) {
if (t->GetSelected() && t->GetKind() == VTrack::Wave) {
waveArray[w++] = (WaveTrack *) t;
if (t->GetMaxLen() > totalTime)
totalTime = t->GetMaxLen();
}
t = iter.Next();
}
WaveTrack *mixLeft = new WaveTrack(dirManager);
mixLeft->SetSampleFormat(format);
mixLeft->SetRate(rate);
mixLeft->SetChannel(VTrack::MonoChannel);
mixLeft->SetName(_("Mix"));
WaveTrack *mixRight = 0;
if (!mono) {
mixRight = new WaveTrack(dirManager);
mixRight->SetSampleFormat(format);
mixRight->SetRate(rate);
mixRight->SetName(_("Mix"));
mixLeft->SetChannel(VTrack::LeftChannel);
mixRight->SetChannel(VTrack::RightChannel);
mixLeft->SetLinked(true);
}
int maxBlockLen = mixLeft->GetIdealBlockSize();
double maxBlockTime = maxBlockLen / mixLeft->GetRate();
Mixer *mixer = new Mixer(mono ? 1 : 2, maxBlockLen, false,
rate, format);
wxProgressDialog *progress = NULL;
wxYield();
wxStartTimer();
wxBusyCursor busy;
double tt = 0.0;
while (tt < totalTime) {
double blockTime = maxBlockTime;
if (tt + blockTime > totalTime)
blockTime = totalTime - tt;
int blockLen = int (blockTime * mixLeft->GetRate());
mixer->Clear();
for (int i = 0; i < numWaves; i++) {
if (mono)
mixer->MixMono(waveArray[i], tt, tt + blockTime);
else {
switch (waveArray[i]->GetChannel()) {
case VTrack::LeftChannel:
mixer->MixLeft(waveArray[i], tt, tt + blockTime);
break;
case VTrack::RightChannel:
mixer->MixRight(waveArray[i], tt, tt + blockTime);
break;
//.........这里部分代码省略.........
示例3: ExportPCM
//.........这里部分代码省略.........
wxProgressDialog *progress = NULL;
wxYield();
wxStartTimer();
wxBusyCursor busy;
bool cancelling = false;
double t = t0;
while (t < t1 && !cancelling) {
double deltat = timeStep;
if (t + deltat > t1)
deltat = t1 - t;
sampleCount numSamples = int (deltat * rate + 0.5);
Mixer *mixer = new Mixer(stereo ? 2 : 1, numSamples, true, rate);
wxASSERT(mixer);
mixer->Clear();
char *buffer = new char[numSamples * 2 * sndbuffer.format.channels];
wxASSERT(buffer);
TrackListIterator iter(tracks);
VTrack *tr = iter.First();
while (tr) {
if (tr->GetKind() == VTrack::Wave) {
if (tr->selected || !selectionOnly) {
if (tr->channel == VTrack::MonoChannel)
mixer->MixMono((WaveTrack *) tr, t, t + deltat);
if (tr->channel == VTrack::LeftChannel)
mixer->MixLeft((WaveTrack *) tr, t, t + deltat);
if (tr->channel == VTrack::RightChannel)
mixer->MixRight((WaveTrack *) tr, t, t + deltat);
}
}
tr = iter.Next();
}
sampleType *mixed = mixer->GetBuffer();
long b2 = snd_convert(&sndfile, buffer, // to
&sndbuffer, mixed, numSamples); // from
snd_write(&sndfile, buffer, b2);
t += deltat;
if (!progress && wxGetElapsedTime(false) > 500) {
wxString message;
if (selectionOnly)
message =
wxString::
Format("Exporting the selected audio as a %s file",
(const char *) format);
else
message =
wxString::
Format("Exporting the entire project as a %s file",
(const char *) format);
progress =
new wxProgressDialog("Export",
message,
示例4: ExportCL
bool ExportCL(AudacityProject *project, bool stereo, wxString fName,
bool selectionOnly, double t0, double t1)
{
int rate = int(project->GetRate() + 0.5);
wxWindow *parent = project;
TrackList *tracks = project->GetTracks();
wxString command = gPrefs->Read("/FileFormats/ExternalProgramExportCommand", "lame - '%f'");
command.Replace("%f", fName);
/* establish parameters */
int channels = stereo ? 2 : 1;
unsigned long totalSamples = (unsigned long)((t1 - t0) * rate + 0.5);
unsigned long sampleBytes = totalSamples * channels * SAMPLE_SIZE(int16Sample);
double timeStep = 10.0; // write in blocks of 10 secs
/* fill up the wav header */
wav_header header;
header.riffID[0] = 'R';
header.riffID[1] = 'I';
header.riffID[2] = 'F';
header.riffID[3] = 'F';
header.riffType[0] = 'W';
header.riffType[1] = 'A';
header.riffType[2] = 'V';
header.riffType[3] = 'E';
header.lenAfterRiff = sampleBytes + 32;
header.fmtID[0] = 'f';
header.fmtID[1] = 'm';
header.fmtID[2] = 't';
header.fmtID[3] = ' ';
header.formatChunkLen = 16;
header.formatTag = 1;
header.channels = channels;
header.sampleRate = rate;
header.bitsPerSample = SAMPLE_SIZE(int16Sample) * 8;
header.blockAlign = header.bitsPerSample * header.channels;
header.avgBytesPerSec = header.sampleRate * header.blockAlign;
header.dataID[0] = 'd';
header.dataID[1] = 'a';
header.dataID[2] = 't';
header.dataID[3] = 'a';
header.dataLen = sampleBytes;
FILE *pipe = popen(command.c_str(), "w");
/* write the header */
fwrite( &header, sizeof(wav_header), 1, pipe );
//sampleCount maxSamples = int (timeStep * rate + 0.5);
wxProgressDialog *progress = NULL;
wxYield();
wxStartTimer();
wxBusyCursor busy;
bool cancelling = false;
double t = t0;
while (t < t1 && !cancelling) {
double deltat = timeStep;
if (t + deltat > t1)
deltat = t1 - t;
sampleCount numSamples = int (deltat * rate + 0.5);
Mixer *mixer = new Mixer(channels, numSamples, true, rate, int16Sample);
wxASSERT(mixer);
mixer->Clear();
char *buffer = new char[numSamples * SAMPLE_SIZE(int16Sample) * channels];
wxASSERT(buffer);
TrackListIterator iter(tracks);
VTrack *tr = iter.First();
while (tr) {
if (tr->GetKind() == VTrack::Wave) {
if (tr->GetSelected() || !selectionOnly) {
if (tr->GetChannel() == VTrack::MonoChannel)
mixer->MixMono((WaveTrack *) tr, t, t + deltat);
if (tr->GetChannel() == VTrack::LeftChannel)
mixer->MixLeft((WaveTrack *) tr, t, t + deltat);
if (tr->GetChannel() == VTrack::RightChannel)
mixer->MixRight((WaveTrack *) tr, t, t + deltat);
}
}
tr = iter.Next();
}
samplePtr mixed = mixer->GetBuffer();
// Byte-swapping is neccesary on big-endian machines, since
// WAV files are little-endian
#if wxBYTE_ORDER == wxBIG_ENDIAN
{
short *buffer = (short*)mixed;
//.........这里部分代码省略.........
示例5: ExportMP3
//.........这里部分代码省略.........
int bufferSize = GetMP3Exporter()->GetOutBufferSize();
unsigned char *buffer = new unsigned char[bufferSize];
wxASSERT(buffer);
while (t < t1 && !cancelling) {
double deltat = timeStep;
bool lastFrame = false;
sampleCount numSamples = inSamples;
if (t + deltat > t1) {
lastFrame = true;
deltat = t1 - t;
numSamples = int(deltat * rate + 0.5);
}
Mixer *mixer = new Mixer(stereo ? 2 : 1, numSamples, true,
rate, int16Sample);
wxASSERT(mixer);
mixer->Clear();
TrackListIterator iter(tracks);
VTrack *tr = iter.First();
while (tr) {
if (tr->GetKind() == VTrack::Wave) {
if (tr->GetSelected() || !selectionOnly) {
if (tr->GetChannel() == VTrack::MonoChannel)
mixer->MixMono((WaveTrack *) tr, t, t + deltat);
else if (tr->GetChannel() == VTrack::LeftChannel)
mixer->MixLeft((WaveTrack *) tr, t, t + deltat);
else if (tr->GetChannel() == VTrack::RightChannel)
mixer->MixRight((WaveTrack *) tr, t, t + deltat);
}
}
tr = iter.Next();
}
short *mixed = (short *)mixer->GetBuffer();
if(lastFrame)
bytes = GetMP3Exporter()->EncodeRemainder(mixed, numSamples, buffer);
else
bytes = GetMP3Exporter()->EncodeBuffer(mixed, buffer);
outFile.Write(buffer, bytes);
t += deltat;
if (!progress && wxGetElapsedTime(false) > 500) {
wxString message;
if (selectionOnly)
message =
wxString::Format(_("Exporting the selected audio as an mp3"));
else
message =
wxString::Format(_("Exporting the entire project as an mp3"));
progress =
new wxProgressDialog(_("Export"),
message,
1000,
parent,
示例6: ExportPCM
bool ExportPCM(AudacityProject *project,
bool stereo, wxString fName,
bool selectionOnly, double t0, double t1)
{
double rate = project->GetRate();
wxWindow *parent = project;
TrackList *tracks = project->GetTracks();
int format = ReadExportFormatPref();
int formatBits = ReadExportFormatBitsPref();
wxString formatStr;
SF_INFO info;
SNDFILE *sf;
int err;
formatStr = sf_header_name(format & SF_FORMAT_TYPEMASK);
// Use libsndfile to export file
info.samplerate = (unsigned int)(rate + 0.5);
info.samples = (unsigned int)((t1 - t0)*rate + 0.5);
info.channels = stereo? 2: 1;
info.pcmbitwidth = formatBits;
info.format = format;
info.sections = 1;
info.seekable = 0;
// If we can't export exactly the format they requested,
// try the default format for that header type, and try
// 16-bit samples.
if (!sf_format_check(&info))
info.format = (info.format & SF_FORMAT_TYPEMASK);
if (!sf_format_check(&info))
info.pcmbitwidth = 16;
if (!sf_format_check(&info)) {
wxMessageBox(_("Cannot export audio in this format."));
return false;
}
sf = sf_open_write((const char *)fName, &info);
if (!sf) {
wxMessageBox(wxString::Format(_("Cannot export audio to %s"),
(const char *)fName));
return false;
}
double timeStep = 10.0; // write in blocks of 10 secs
wxProgressDialog *progress = NULL;
wxYield();
wxStartTimer();
wxBusyCursor busy;
bool cancelling = false;
double t = t0;
while (t < t1 && !cancelling) {
double deltat = timeStep;
if (t + deltat > t1)
deltat = t1 - t;
sampleCount numSamples = int (deltat * rate + 0.5);
Mixer *mixer = new Mixer(stereo ? 2 : 1, numSamples, true, rate);
wxASSERT(mixer);
mixer->Clear();
TrackListIterator iter(tracks);
VTrack *tr = iter.First();
while (tr) {
if (tr->GetKind() == VTrack::Wave) {
if (tr->GetSelected() || !selectionOnly) {
if (tr->GetChannel() == VTrack::MonoChannel)
mixer->MixMono((WaveTrack *) tr, t, t + deltat);
if (tr->GetChannel() == VTrack::LeftChannel)
mixer->MixLeft((WaveTrack *) tr, t, t + deltat);
if (tr->GetChannel() == VTrack::RightChannel)
mixer->MixRight((WaveTrack *) tr, t, t + deltat);
}
}
tr = iter.Next();
}
sampleType *mixed = mixer->GetBuffer();
sf_writef_short(sf, mixed, numSamples);
t += deltat;
if (!progress && wxGetElapsedTime(false) > 500) {
wxString message;
if (selectionOnly)
message =
wxString::
Format(_("Exporting the selected audio as a %s file"),
(const char *) formatStr);
else
message =
//.........这里部分代码省略.........
示例7: FillBuffers
void AudioIO::FillBuffers()
{
unsigned int numEmpty = 0;
unsigned int i;
// Playback buffers
for(i=0; i<mNumOutBuffers; i++) {
if (mOutBuffer[i].ID == 0)
numEmpty++;
}
if (numEmpty > (mNumOutBuffers/2)) {
sampleCount block = numEmpty * mBufferSize;
double deltat = block / mRate;
if (mT + deltat > mT1) {
deltat = mT1 - mT;
if(deltat < 0.0) return;
block = (sampleCount)(deltat * mRate + 0.5);
}
Mixer *mixer = new Mixer(mNumOutChannels, block, true,
mRate, mFormat);
mixer->UseVolumeSlider(mProject->GetControlToolBar());
mixer->Clear();
TrackListIterator iter2(mTracks);
int numSolo = 0;
Track *vt = iter2.First();
while (vt) {
if (vt->GetKind() == Track::Wave && vt->GetSolo())
numSolo++;
vt = iter2.Next();
}
TrackListIterator iter(mTracks);
vt = iter.First();
while (vt) {
if (vt->GetKind() == Track::Wave) {
Track *mt = vt;
// We want to extract mute and solo information from
// the top of the two tracks if they're linked
// (i.e. a stereo pair only has one set of mute/solo buttons)
Track *partner = mTracks->GetLink(vt);
if (partner && !vt->GetLinked())
mt = partner;
else
mt = vt;
// Cut if somebody else is soloing
if (numSolo>0 && !mt->GetSolo()) {
vt = iter.Next();
continue;
}
// Cut if we're muted (unless we're soloing)
if (mt->GetMute() && !mt->GetSolo()) {
vt = iter.Next();
continue;
}
WaveTrack *t = (WaveTrack *) vt;
switch (t->GetChannel()) {
case Track::LeftChannel:
mixer->MixLeft(t, mT, mT + deltat);
break;
case Track::RightChannel:
mixer->MixRight(t, mT, mT + deltat);
break;
case Track::MonoChannel:
mixer->MixMono(t, mT, mT + deltat);
break;
}
}
vt = iter.Next();
}
// Copy the mixed samples into the buffers
samplePtr outbytes = mixer->GetBuffer();
for(i=0; i<mNumOutBuffers && block>0; i++)
if (mOutBuffer[i].ID == 0) {
sampleCount count;
if (block > mBufferSize)
count = mBufferSize;
else
count = block;
memcpy(mOutBuffer[i].data, outbytes,
count*mNumOutChannels*SAMPLE_SIZE(mFormat));
block -= count;
outbytes += (count*mNumOutChannels*SAMPLE_SIZE(mFormat));
mOutBuffer[i].len = count;
mOutBuffer[i].ID = mOutID;
//.........这里部分代码省略.........