1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-25 15:53:52 +02:00

Stack-allocate where possible! ...

... Removed many unnecessary naked news and deletes.
This commit is contained in:
Paul Licameli
2016-01-31 20:39:24 -05:00
parent be1d9b7dd5
commit dbaa811577
43 changed files with 785 additions and 839 deletions

View File

@@ -440,59 +440,59 @@ int ExportCL::Export(AudacityProject *project,
samplePtr mixed = NULL;
int updateResult = eProgressSuccess;
// Prepare the progress display
ProgressDialog *progress = new ProgressDialog(_("Export"),
selectionOnly ?
_("Exporting the selected audio using command-line encoder") :
_("Exporting the entire project using command-line encoder"));
{
// Prepare the progress display
ProgressDialog progress(_("Export"),
selectionOnly ?
_("Exporting the selected audio using command-line encoder") :
_("Exporting the entire project using command-line encoder"));
// Start piping the mixed data to the command
while (updateResult == eProgressSuccess && process.IsActive() && os->IsOk()) {
// Capture any stdout and stderr from the command
Drain(process.GetInputStream(), &output);
Drain(process.GetErrorStream(), &output);
// Start piping the mixed data to the command
while (updateResult == eProgressSuccess && process.IsActive() && os->IsOk()) {
// Capture any stdout and stderr from the command
Drain(process.GetInputStream(), &output);
Drain(process.GetErrorStream(), &output);
// Need to mix another block
if (numBytes == 0) {
sampleCount numSamples = mixer->Process(maxBlockLen);
if (numSamples == 0) {
break;
}
// Need to mix another block
if (numBytes == 0) {
sampleCount numSamples = mixer->Process(maxBlockLen);
if (numSamples == 0) {
break;
}
mixed = mixer->GetBuffer();
numBytes = numSamples * channels;
mixed = mixer->GetBuffer();
numBytes = numSamples * channels;
// Byte-swapping is neccesary on big-endian machines, since
// WAV files are little-endian
// Byte-swapping is neccesary on big-endian machines, since
// WAV files are little-endian
#if wxBYTE_ORDER == wxBIG_ENDIAN
wxUint16 *buffer = (wxUint16 *) mixed;
for (int i = 0; i < numBytes; i++) {
buffer[i] = wxUINT16_SWAP_ON_BE(buffer[i]);
}
wxUint16 *buffer = (wxUint16 *) mixed;
for (int i = 0; i < numBytes; i++) {
buffer[i] = wxUINT16_SWAP_ON_BE(buffer[i]);
}
#endif
numBytes *= SAMPLE_SIZE(int16Sample);
}
// Don't write too much at once...pipes may not be able to handle it
size_t bytes = wxMin(numBytes, 4096);
numBytes -= bytes;
while (bytes > 0) {
os->Write(mixed, bytes);
if (!os->IsOk()) {
break;
numBytes *= SAMPLE_SIZE(int16Sample);
}
bytes -= os->LastWrite();
mixed += os->LastWrite();
// Don't write too much at once...pipes may not be able to handle it
size_t bytes = wxMin(numBytes, 4096);
numBytes -= bytes;
while (bytes > 0) {
os->Write(mixed, bytes);
if (!os->IsOk()) {
break;
}
bytes -= os->LastWrite();
mixed += os->LastWrite();
}
// Update the progress display
updateResult = progress.Update(mixer->MixGetCurrentTime() - t0, t1 - t0);
}
// Update the progress display
updateResult = progress->Update(mixer->MixGetCurrentTime()-t0, t1-t0);
// Done with the progress display
}
// Done with the progress display
delete progress;
// Should make the process die
process.CloseOutput();

View File

@@ -831,30 +831,29 @@ int ExportFFmpeg::Export(AudacityProject *project,
t0, t1,
channels, pcmBufferSize, true,
mSampleRate, int16Sample, true, mixerSpec);
delete [] waveTracks;
ProgressDialog *progress = new ProgressDialog(wxFileName(fName).GetName(),
selectionOnly ?
wxString::Format(_("Exporting selected audio as %s"), ExportFFmpegOptions::fmts[mSubFormat].description) :
wxString::Format(_("Exporting entire file as %s"), ExportFFmpegOptions::fmts[mSubFormat].description));
delete[] waveTracks;
int updateResult = eProgressSuccess;
{
ProgressDialog progress(wxFileName(fName).GetName(),
selectionOnly ?
wxString::Format(_("Exporting selected audio as %s"), ExportFFmpegOptions::fmts[mSubFormat].description) :
wxString::Format(_("Exporting entire file as %s"), ExportFFmpegOptions::fmts[mSubFormat].description));
while(updateResult == eProgressSuccess) {
sampleCount pcmNumSamples = mixer->Process(pcmBufferSize);
while (updateResult == eProgressSuccess) {
sampleCount pcmNumSamples = mixer->Process(pcmBufferSize);
if (pcmNumSamples == 0)
break;
if (pcmNumSamples == 0)
break;
short *pcmBuffer = (short *)mixer->GetBuffer();
short *pcmBuffer = (short *)mixer->GetBuffer();
EncodeAudioFrame(pcmBuffer,(pcmNumSamples)*sizeof(int16_t)*mChannels);
EncodeAudioFrame(pcmBuffer, (pcmNumSamples)*sizeof(int16_t)*mChannels);
updateResult = progress->Update(mixer->MixGetCurrentTime()-t0, t1-t0);
updateResult = progress.Update(mixer->MixGetCurrentTime() - t0, t1 - t0);
}
}
delete progress;
delete mixer;
Finalize();

View File

@@ -325,38 +325,38 @@ int ExportFLAC::Export(AudacityProject *project,
tmpsmplbuf[i] = (FLAC__int32 *) calloc(SAMPLES_PER_RUN, sizeof(FLAC__int32));
}
ProgressDialog *progress = new ProgressDialog(wxFileName(fName).GetName(),
{
ProgressDialog progress(wxFileName(fName).GetName(),
selectionOnly ?
_("Exporting the selected audio as FLAC") :
_("Exporting the entire project as FLAC"));
while (updateResult == eProgressSuccess) {
sampleCount samplesThisRun = mixer->Process(SAMPLES_PER_RUN);
if (samplesThisRun == 0) { //stop encoding
break;
}
else {
for (i = 0; i < numChannels; i++) {
samplePtr mixed = mixer->GetBuffer(i);
if (format == int24Sample) {
for (j = 0; j < samplesThisRun; j++) {
tmpsmplbuf[i][j] = ((int *) mixed)[j];
}
}
else {
for (j = 0; j < samplesThisRun; j++) {
tmpsmplbuf[i][j] = ((short *) mixed)[j];
}
}
while (updateResult == eProgressSuccess) {
sampleCount samplesThisRun = mixer->Process(SAMPLES_PER_RUN);
if (samplesThisRun == 0) { //stop encoding
break;
}
encoder.process(tmpsmplbuf, samplesThisRun);
else {
for (i = 0; i < numChannels; i++) {
samplePtr mixed = mixer->GetBuffer(i);
if (format == int24Sample) {
for (j = 0; j < samplesThisRun; j++) {
tmpsmplbuf[i][j] = ((int *)mixed)[j];
}
}
else {
for (j = 0; j < samplesThisRun; j++) {
tmpsmplbuf[i][j] = ((short *)mixed)[j];
}
}
}
encoder.process(tmpsmplbuf, samplesThisRun);
}
updateResult = progress.Update(mixer->MixGetCurrentTime() - t0, t1 - t0);
}
updateResult = progress->Update(mixer->MixGetCurrentTime()-t0, t1-t0);
f.Detach(); // libflac closes the file
encoder.finish();
}
f.Detach(); // libflac closes the file
encoder.finish();
delete progress;
for (i = 0; i < numChannels; i++) {
free(tmpsmplbuf[i]);

View File

@@ -272,36 +272,36 @@ int ExportMP2::Export(AudacityProject *project,
t0, t1,
stereo? 2: 1, pcmBufferSize, true,
rate, int16Sample, true, mixerSpec);
delete [] waveTracks;
ProgressDialog *progress = new ProgressDialog(wxFileName(fName).GetName(),
selectionOnly ?
wxString::Format(_("Exporting selected audio at %ld kbps"), bitrate) :
wxString::Format(_("Exporting entire file at %ld kbps"), bitrate));
delete[] waveTracks;
int updateResult = eProgressSuccess;
while(updateResult == eProgressSuccess) {
sampleCount pcmNumSamples = mixer->Process(pcmBufferSize);
{
ProgressDialog progress(wxFileName(fName).GetName(),
selectionOnly ?
wxString::Format(_("Exporting selected audio at %ld kbps"), bitrate) :
wxString::Format(_("Exporting entire file at %ld kbps"), bitrate));
if (pcmNumSamples == 0)
break;
while (updateResult == eProgressSuccess) {
sampleCount pcmNumSamples = mixer->Process(pcmBufferSize);
short *pcmBuffer = (short *)mixer->GetBuffer();
if (pcmNumSamples == 0)
break;
int mp2BufferNumBytes = twolame_encode_buffer_interleaved(
short *pcmBuffer = (short *)mixer->GetBuffer();
int mp2BufferNumBytes = twolame_encode_buffer_interleaved(
encodeOptions,
pcmBuffer,
pcmNumSamples,
mp2Buffer,
mp2BufferSize);
outFile.Write(mp2Buffer, mp2BufferNumBytes);
outFile.Write(mp2Buffer, mp2BufferNumBytes);
updateResult = progress->Update(mixer->MixGetCurrentTime()-t0, t1-t0);
updateResult = progress.Update(mixer->MixGetCurrentTime() - t0, t1 - t0);
}
}
delete progress;
delete mixer;
int mp2BufferNumBytes = twolame_encode_flush(

View File

@@ -1792,48 +1792,48 @@ int ExportMP3::Export(AudacityProject *project,
brate);
}
ProgressDialog *progress = new ProgressDialog(wxFileName(fName).GetName(), title);
{
ProgressDialog progress(wxFileName(fName).GetName(), title);
while (updateResult == eProgressSuccess) {
sampleCount blockLen = mixer->Process(inSamples);
while (updateResult == eProgressSuccess) {
sampleCount blockLen = mixer->Process(inSamples);
if (blockLen == 0) {
break;
}
if (blockLen == 0) {
break;
}
short *mixed = (short *)mixer->GetBuffer();
short *mixed = (short *)mixer->GetBuffer();
if (blockLen < inSamples) {
if (channels > 1) {
bytes = exporter.EncodeRemainder(mixed, blockLen , buffer);
if (blockLen < inSamples) {
if (channels > 1) {
bytes = exporter.EncodeRemainder(mixed, blockLen, buffer);
}
else {
bytes = exporter.EncodeRemainderMono(mixed, blockLen, buffer);
}
}
else {
bytes = exporter.EncodeRemainderMono(mixed, blockLen , buffer);
if (channels > 1) {
bytes = exporter.EncodeBuffer(mixed, buffer);
}
else {
bytes = exporter.EncodeBufferMono(mixed, buffer);
}
}
}
else {
if (channels > 1) {
bytes = exporter.EncodeBuffer(mixed, buffer);
}
else {
bytes = exporter.EncodeBufferMono(mixed, buffer);
if (bytes < 0) {
wxString msg;
msg.Printf(_("Error %ld returned from MP3 encoder"), bytes);
wxMessageBox(msg);
break;
}
outFile.Write(buffer, bytes);
updateResult = progress.Update(mixer->MixGetCurrentTime() - t0, t1 - t0);
}
if (bytes < 0) {
wxString msg;
msg.Printf(_("Error %ld returned from MP3 encoder"), bytes);
wxMessageBox(msg);
break;
}
outFile.Write(buffer, bytes);
updateResult = progress->Update(mixer->MixGetCurrentTime()-t0, t1-t0);
}
delete progress;
delete mixer;
bytes = exporter.FinishStream(buffer);

View File

@@ -253,74 +253,74 @@ int ExportOGG::Export(AudacityProject *project,
t0, t1,
numChannels, SAMPLES_PER_RUN, false,
rate, floatSample, true, mixerSpec);
delete [] waveTracks;
delete[] waveTracks;
ProgressDialog *progress = new ProgressDialog(wxFileName(fName).GetName(),
selectionOnly ?
_("Exporting the selected audio as Ogg Vorbis") :
_("Exporting the entire project as Ogg Vorbis"));
{
ProgressDialog progress(wxFileName(fName).GetName(),
selectionOnly ?
_("Exporting the selected audio as Ogg Vorbis") :
_("Exporting the entire project as Ogg Vorbis"));
while (updateResult == eProgressSuccess && !eos) {
float **vorbis_buffer = vorbis_analysis_buffer(&dsp, SAMPLES_PER_RUN);
sampleCount samplesThisRun = mixer->Process(SAMPLES_PER_RUN);
while (updateResult == eProgressSuccess && !eos) {
float **vorbis_buffer = vorbis_analysis_buffer(&dsp, SAMPLES_PER_RUN);
sampleCount samplesThisRun = mixer->Process(SAMPLES_PER_RUN);
if (samplesThisRun == 0) {
// Tell the library that we wrote 0 bytes - signalling the end.
vorbis_analysis_wrote(&dsp, 0);
}
else {
if (samplesThisRun == 0) {
// Tell the library that we wrote 0 bytes - signalling the end.
vorbis_analysis_wrote(&dsp, 0);
}
else {
for (int i = 0; i < numChannels; i++) {
float *temp = (float *)mixer->GetBuffer(i);
memcpy(vorbis_buffer[i], temp, sizeof(float)*SAMPLES_PER_RUN);
for (int i = 0; i < numChannels; i++) {
float *temp = (float *)mixer->GetBuffer(i);
memcpy(vorbis_buffer[i], temp, sizeof(float)*SAMPLES_PER_RUN);
}
// tell the encoder how many samples we have
vorbis_analysis_wrote(&dsp, samplesThisRun);
}
// 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) {
// 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);
// analysis, assume we want to use bitrate management
vorbis_analysis(&block, NULL);
vorbis_bitrate_addblock(&block);
while (vorbis_bitrate_flushpacket(&dsp, &packet)) {
while (vorbis_bitrate_flushpacket(&dsp, &packet)) {
// add the packet to the bitstream
ogg_stream_packetin(&stream, &packet);
// add the packet to the bitstream
ogg_stream_packetin(&stream, &packet);
// From vorbis-tools-1.0/oggenc/encode.c:
// If we've gone over a page boundary, we can do actual output,
// so do so (for however many pages are available).
// From vorbis-tools-1.0/oggenc/encode.c:
// If we've gone over a page boundary, we can do actual output,
// so do so (for however many pages are available).
while (!eos) {
int result = ogg_stream_pageout(&stream, &page);
if (!result) {
break;
}
while (!eos) {
int result = ogg_stream_pageout(&stream, &page);
if (!result) {
break;
}
outFile.Write(page.header, page.header_len);
outFile.Write(page.body, page.body_len);
outFile.Write(page.header, page.header_len);
outFile.Write(page.body, page.body_len);
if (ogg_page_eos(&page)) {
eos = 1;
if (ogg_page_eos(&page)) {
eos = 1;
}
}
}
}
updateResult = progress.Update(mixer->MixGetCurrentTime() - t0, t1 - t0);
}
updateResult = progress->Update(mixer->MixGetCurrentTime()-t0, t1-t0);
}
delete progress;;
delete mixer;
ogg_stream_clear(&stream);

View File

@@ -493,47 +493,47 @@ int ExportPCM::Export(AudacityProject *project,
info.channels, maxBlockLen, true,
rate, format, true, mixerSpec);
ProgressDialog *progress = new ProgressDialog(wxFileName(fName).GetName(),
selectionOnly ?
wxString::Format(_("Exporting the selected audio as %s"),
formatStr.c_str()) :
wxString::Format(_("Exporting the entire project as %s"),
formatStr.c_str()));
{
ProgressDialog progress(wxFileName(fName).GetName(),
selectionOnly ?
wxString::Format(_("Exporting the selected audio as %s"),
formatStr.c_str()) :
wxString::Format(_("Exporting the entire project as %s"),
formatStr.c_str()));
while(updateResult == eProgressSuccess) {
sampleCount samplesWritten;
sampleCount numSamples = mixer->Process(maxBlockLen);
while (updateResult == eProgressSuccess) {
sampleCount samplesWritten;
sampleCount numSamples = mixer->Process(maxBlockLen);
if (numSamples == 0)
break;
if (numSamples == 0)
break;
samplePtr mixed = mixer->GetBuffer();
samplePtr mixed = mixer->GetBuffer();
ODManager::LockLibSndFileMutex();
if (format == int16Sample)
samplesWritten = sf_writef_short(sf, (short *)mixed, numSamples);
else
samplesWritten = sf_writef_float(sf, (float *)mixed, numSamples);
ODManager::UnlockLibSndFileMutex();
ODManager::LockLibSndFileMutex();
if (format == int16Sample)
samplesWritten = sf_writef_short(sf, (short *)mixed, numSamples);
else
samplesWritten = sf_writef_float(sf, (float *)mixed, numSamples);
ODManager::UnlockLibSndFileMutex();
if (samplesWritten != numSamples) {
char buffer2[1000];
sf_error_str(sf, buffer2, 1000);
wxMessageBox(wxString::Format(
/* i18n-hint: %s will be the error message from libsndfile, which
* is usually something unhelpful (and untranslated) like "system
* error" */
_("Error while writing %s file (disk full?).\nLibsndfile says \"%s\""),
formatStr.c_str(),
wxString::FromAscii(buffer2).c_str()));
break;
if (samplesWritten != numSamples) {
char buffer2[1000];
sf_error_str(sf, buffer2, 1000);
wxMessageBox(wxString::Format(
/* i18n-hint: %s will be the error message from libsndfile, which
* is usually something unhelpful (and untranslated) like "system
* error" */
_("Error while writing %s file (disk full?).\nLibsndfile says \"%s\""),
formatStr.c_str(),
wxString::FromAscii(buffer2).c_str()));
break;
}
updateResult = progress.Update(mixer->MixGetCurrentTime() - t0, t1 - t0);
}
updateResult = progress->Update(mixer->MixGetCurrentTime()-t0, t1-t0);
}
delete progress;
delete mixer;
delete[] waveTracks;