Audacity  2.2.2
Public Member Functions | Private Member Functions | List of all members
ExportMP3 Class Referencefinal
Inheritance diagram for ExportMP3:
ExportPlugin

Public Member Functions

 ExportMP3 ()
 
bool CheckFileName (wxFileName &filename, int format)
 
wxWindow * OptionsCreate (wxWindow *parent, int format) override
 
ProgressResult Export (AudacityProject *project, unsigned channels, const wxString &fName, bool selectedOnly, double t0, double t1, MixerSpec *mixerSpec=NULL, const Tags *metadata=NULL, int subformat=0) override
 called to export audio into a file. More...
 
- Public Member Functions inherited from ExportPlugin
 ExportPlugin ()
 
virtual ~ExportPlugin ()
 
int AddFormat ()
 Add a NEW entry to the list of formats this plug-in can export. More...
 
void SetFormat (const wxString &format, int index)
 
void SetDescription (const wxString &description, int index)
 
void AddExtension (const wxString &extension, int index)
 
void SetExtensions (const wxArrayString &extensions, int index)
 
void SetMask (const wxString &mask, int index)
 
void SetMaxChannels (unsigned maxchannels, unsigned index)
 
void SetCanMetaData (bool canmetadata, int index)
 
virtual int GetFormatCount ()
 
virtual wxString GetFormat (int index)
 
virtual wxString GetDescription (int index)
 
virtual wxString GetExtension (int index=0)
 Return the (first) file name extension for the sub-format. More...
 
virtual wxArrayString GetExtensions (int index=0)
 Return all the file name extensions used for the sub-format. More...
 
virtual wxString GetMask (int index)
 
virtual unsigned GetMaxChannels (int index)
 
virtual bool GetCanMetaData (int index)
 
virtual bool IsExtension (const wxString &ext, int index)
 
virtual bool DisplayOptions (wxWindow *parent, int format=0)
 

Private Member Functions

int FindValue (CHOICES *choices, int cnt, int needle, int def)
 
wxString FindName (CHOICES *choices, int cnt, int needle)
 
int AskResample (int bitrate, int rate, int lowrate, int highrate)
 
int AddTags (AudacityProject *project, ArrayOf< char > &buffer, bool *endOfFile, const Tags *tags)
 
int SetNumExportChannels () override
 Exporter plug-ins may override this to specify the number of channels in exported file. -1 for unspecified. More...
 

Additional Inherited Members

- Protected Member Functions inherited from ExportPlugin
std::unique_ptr< MixerCreateMixer (const WaveTrackConstArray &inputTracks, const TimeTrack *timeTrack, double startTime, double stopTime, unsigned numOutChannels, size_t outBufferSize, bool outInterleaved, double outRate, sampleFormat outFormat, bool highQuality=true, MixerSpec *mixerSpec=NULL)
 

Detailed Description

Definition at line 1595 of file ExportMP3.cpp.

Constructor & Destructor Documentation

ExportMP3::ExportMP3 ( )

Definition at line 1627 of file ExportMP3.cpp.

References _(), ExportPlugin::AddExtension(), ExportPlugin::AddFormat(), InitMP3_Statics(), ExportPlugin::SetCanMetaData(), ExportPlugin::SetDescription(), ExportPlugin::SetFormat(), and ExportPlugin::SetMaxChannels().

1628 : ExportPlugin()
1629 {
1630  InitMP3_Statics();
1631  AddFormat();
1632  SetFormat(wxT("MP3"),0);
1633  AddExtension(wxT("mp3"),0);
1634  SetMaxChannels(2,0);
1635  SetCanMetaData(true,0);
1636  SetDescription(_("MP3 Files"),0);
1637 }
void SetDescription(const wxString &description, int index)
Definition: Export.cpp:124
void SetFormat(const wxString &format, int index)
Definition: Export.cpp:119
static void InitMP3_Statics()
Definition: ExportMP3.cpp:219
void SetMaxChannels(unsigned maxchannels, unsigned index)
Definition: Export.cpp:144
ExportPlugin()
Definition: Export.cpp:81
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
int AddFormat()
Add a NEW entry to the list of formats this plug-in can export.
Definition: Export.cpp:103
void SetCanMetaData(bool canmetadata, int index)
Definition: Export.cpp:149
void AddExtension(const wxString &extension, int index)
Definition: Export.cpp:129

Member Function Documentation

int ExportMP3::AddTags ( AudacityProject project,
ArrayOf< char > &  buffer,
bool *  endOfFile,
const Tags tags 
)
private

Definition at line 2020 of file ExportMP3.cpp.

References Tags::GetRange(), name, ArrayOf< X >::reinit(), TAG_ALBUM, TAG_ARTIST, TAG_COMMENTS, TAG_GENRE, TAG_TITLE, TAG_TRACK, and TAG_YEAR.

Referenced by Export().

2021 {
2022 #ifdef USE_LIBID3TAG
2023  id3_tag_holder tp { id3_tag_new() };
2024 
2025  for (const auto &pair : tags->GetRange()) {
2026  const auto &n = pair.first;
2027  const auto &v = pair.second;
2028  const char *name = "TXXX";
2029 
2030  if (n.CmpNoCase(TAG_TITLE) == 0) {
2031  name = ID3_FRAME_TITLE;
2032  }
2033  else if (n.CmpNoCase(TAG_ARTIST) == 0) {
2034  name = ID3_FRAME_ARTIST;
2035  }
2036  else if (n.CmpNoCase(TAG_ALBUM) == 0) {
2037  name = ID3_FRAME_ALBUM;
2038  }
2039  else if (n.CmpNoCase(TAG_YEAR) == 0) {
2040  // LLL: Some apps do not like the newer frame ID (ID3_FRAME_YEAR),
2041  // so we add old one as well.
2042  AddFrame(tp.get(), n, v, "TYER");
2043  name = ID3_FRAME_YEAR;
2044  }
2045  else if (n.CmpNoCase(TAG_GENRE) == 0) {
2046  name = ID3_FRAME_GENRE;
2047  }
2048  else if (n.CmpNoCase(TAG_COMMENTS) == 0) {
2049  name = ID3_FRAME_COMMENT;
2050  }
2051  else if (n.CmpNoCase(TAG_TRACK) == 0) {
2052  name = ID3_FRAME_TRACK;
2053  }
2054 
2055  AddFrame(tp.get(), n, v, name);
2056  }
2057 
2058  tp->options &= (~ID3_TAG_OPTION_COMPRESSION); // No compression
2059 
2060  // If this version of libid3tag supports it, use v2.3 ID3
2061  // tags instead of the newer, but less well supported, v2.4
2062  // that libid3tag uses by default.
2063  #ifdef ID3_TAG_HAS_TAG_OPTION_ID3V2_3
2064  tp->options |= ID3_TAG_OPTION_ID3V2_3;
2065  #endif
2066 
2067  *endOfFile = false;
2068 
2069  id3_length_t len;
2070 
2071  len = id3_tag_render(tp.get(), 0);
2072  buffer.reinit(len);
2073  len = id3_tag_render(tp.get(), (id3_byte_t *)buffer.get());
2074 
2075  return len;
2076 #else //ifdef USE_LIBID3TAG
2077  return 0;
2078 #endif
2079 }
#define TAG_TRACK
Definition: Tags.h:65
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:499
#define TAG_TITLE
Definition: Tags.h:62
#define TAG_ARTIST
Definition: Tags.h:63
const wxChar * name
Definition: Distortion.cpp:94
#define TAG_COMMENTS
Definition: Tags.h:68
#define TAG_GENRE
Definition: Tags.h:67
Iterators GetRange() const
Definition: Tags.cpp:444
#define TAG_ALBUM
Definition: Tags.h:64
#define TAG_YEAR
Definition: Tags.h:66
int ExportMP3::AskResample ( int  bitrate,
int  rate,
int  lowrate,
int  highrate 
)
private

Definition at line 1943 of file ExportMP3.cpp.

References _(), ShuttleGuiBase::AddChoice(), ShuttleGui::AddStandardButtons(), ShuttleGuiBase::AddTitle(), eIsCreating, ShuttleGuiBase::EndHorizontalLay(), ShuttleGuiBase::EndStatic(), ShuttleGuiBase::EndVerticalLay(), CHOICES::label, label, name, CHOICES::name, ShuttleGuiBase::SetBorder(), ShuttleGuiBase::StartHorizontalLay(), ShuttleGuiBase::StartStatic(), and ShuttleGuiBase::StartVerticalLay().

Referenced by Export().

1944 {
1945  wxDialogWrapper d(nullptr, wxID_ANY, wxString(_("Invalid sample rate")));
1946  d.SetName(d.GetTitle());
1947  wxChoice *choice;
1948  ShuttleGui S(&d, eIsCreating);
1949  wxString text;
1950 
1951  S.StartVerticalLay();
1952  {
1953  S.SetBorder(10);
1954  S.StartStatic(_("Resample"));
1955  {
1956  S.StartHorizontalLay(wxALIGN_CENTER, false);
1957  {
1958  if (bitrate == 0) {
1959  text.Printf(_("The project sample rate (%d) is not supported by the MP3\nfile format. "), rate);
1960  }
1961  else {
1962  text.Printf(_("The project sample rate (%d) and bit rate (%d kbps) combination is not\nsupported by the MP3 file format. "), rate, bitrate);
1963  }
1964 
1965  text += _("You may resample to one of the rates below.");
1966  S.AddTitle(text);
1967  }
1968  S.EndHorizontalLay();
1969 
1970  wxArrayString choices;
1971  wxString selected = wxT("");
1972  for (size_t i = 0; i < WXSIZEOF(sampRates); i++) {
1973  int label = sampRates[i].label;
1974  if (label >= lowrate && label <= highrate) {
1975  choices.Add(sampRates[i].name);
1976  if (label <= rate) {
1977  selected = sampRates[i].name;
1978  }
1979  }
1980  }
1981 
1982  if (selected.IsEmpty()) {
1983  selected = choices[0];
1984  }
1985 
1986  S.StartHorizontalLay(wxALIGN_CENTER, false);
1987  {
1988  choice = S.AddChoice(_("Sample Rates"),
1989  selected,
1990  &choices);
1991  }
1992  S.EndHorizontalLay();
1993  }
1994  S.EndStatic();
1995 
1996  S.AddStandardButtons();
1997  }
1998  S.EndVerticalLay();
1999 
2000  d.Layout();
2001  d.Fit();
2002  d.SetMinSize(d.GetSize());
2003  d.Center();
2004 
2005  if (d.ShowModal() == wxID_CANCEL) {
2006  return 0;
2007  }
2008 
2009  return wxAtoi(choice->GetStringSelection());
2010 }
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:366
wxString label
Definition: Tags.cpp:727
static CHOICES sampRates[]
Definition: ExportMP3.cpp:199
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
const wxChar * name
Definition: Distortion.cpp:94
wxString name
Definition: ExportMP3.cpp:144
int label
Definition: ExportMP3.cpp:145
bool ExportMP3::CheckFileName ( wxFileName &  filename,
int  format 
)
virtual

Reimplemented from ExportPlugin.

Definition at line 1639 of file ExportMP3.cpp.

References _(), AudacityMessageBox(), gPrefs, MP3Exporter::LoadLibrary(), and MP3Exporter::Maybe.

1640 {
1641 #ifndef DISABLE_DYNAMIC_LOADING_LAME
1642  MP3Exporter exporter;
1643 
1644  if (!exporter.LoadLibrary(wxTheApp->GetTopWindow(), MP3Exporter::Maybe)) {
1645  AudacityMessageBox(_("Could not open MP3 encoding library!"));
1646  gPrefs->Write(wxT("/MP3/MP3LibPath"), wxString(wxT("")));
1647  gPrefs->Flush();
1648 
1649  return false;
1650  }
1651 #endif // DISABLE_DYNAMIC_LOADING_LAME
1652 
1653  return true;
1654 }
bool LoadLibrary(wxWindow *parent, AskUser askuser)
Definition: ExportMP3.cpp:986
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
wxFileConfig * gPrefs
Definition: Prefs.cpp:72
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
Class used to export MP3 files.
Definition: ExportMP3.cpp:802
ProgressResult ExportMP3::Export ( AudacityProject project,
unsigned  channels,
const wxString &  fName,
bool  selectedOnly,
double  t0,
double  t1,
MixerSpec mixerSpec = NULL,
const Tags metadata = NULL,
int  subformat = 0 
)
overridevirtual

called to export audio into a file.

Parameters
selectedOnlySet to true if all tracks should be mixed, to false if only the selected tracks should be mixed and exported.
metadataA Tags object that will over-ride the one in *project and be used to tag the file that is exported.
subformatControl which of the multiple formats this exporter is capable of exporting should be used. Used where a single export plug-in handles a number of related formats, but they have separate entries in the Format drop-down list box. For example, the options to export to "Other PCM", "AIFF 16 Bit" and "WAV 16 Bit" are all the same libsndfile export plug-in, but with subformat set to 0, 1, and 2 respectively.

Implements ExportPlugin.

Definition at line 1665 of file ExportMP3.cpp.

References _(), AddTags(), AskResample(), AudacityMessageBox(), Cancelled, CHANNEL_JOINT, CHANNEL_MONO, CHANNEL_STEREO, ExportPlugin::CreateMixer(), MP3Exporter::EncodeBuffer(), MP3Exporter::EncodeBufferMono(), MP3Exporter::EncodeRemainder(), MP3Exporter::EncodeRemainderMono(), FindName(), FindValue(), MP3Exporter::FinishStream(), MP3Exporter::GetOutBufferSize(), AudacityProject::GetRate(), AudacityProject::GetTags(), TrackList::GetTimeTrack(), AudacityProject::GetTracks(), TrackList::GetWaveTrackConstArray(), gPrefs, MP3Exporter::InitializeStream(), MP3Exporter::InitLibrary(), MP3Exporter::LoadLibrary(), lrint, MP3Exporter::Maybe, MODE_ABR, MODE_CBR, MODE_SET, MODE_VBR, PRESET_STANDARD, MP3Exporter::PutInfoTag(), QUALITY_2, ROUTINE_FAST, MP3Exporter::SetBitrate(), MP3Exporter::SetChannel(), MP3Exporter::SetMode(), MP3Exporter::SetQuality(), Success, ProgressDialog::Update(), and MP3Exporter::ValidLibraryLoaded().

1674 {
1675  int rate = lrint(project->GetRate());
1676 #ifndef DISABLE_DYNAMIC_LOADING_LAME
1677  wxWindow *parent = project;
1678 #endif // DISABLE_DYNAMIC_LOADING_LAME
1679  const TrackList *tracks = project->GetTracks();
1680  MP3Exporter exporter;
1681 
1682 #ifdef DISABLE_DYNAMIC_LOADING_LAME
1683  if (!exporter.InitLibrary(wxT(""))) {
1684  AudacityMessageBox(_("Could not initialize MP3 encoding library!"));
1685  gPrefs->Write(wxT("/MP3/MP3LibPath"), wxString(wxT("")));
1686  gPrefs->Flush();
1687 
1689  }
1690 #else
1691  if (!exporter.LoadLibrary(parent, MP3Exporter::Maybe)) {
1692  AudacityMessageBox(_("Could not open MP3 encoding library!"));
1693  gPrefs->Write(wxT("/MP3/MP3LibPath"), wxString(wxT("")));
1694  gPrefs->Flush();
1695 
1697  }
1698 
1699  if (!exporter.ValidLibraryLoaded()) {
1700  AudacityMessageBox(_("Not a valid or supported MP3 encoding library!"));
1701  gPrefs->Write(wxT("/MP3/MP3LibPath"), wxString(wxT("")));
1702  gPrefs->Flush();
1703 
1705  }
1706 #endif // DISABLE_DYNAMIC_LOADING_LAME
1707 
1708  // Retrieve preferences
1709  int highrate = 48000;
1710  int lowrate = 8000;
1711  int bitrate = 0;
1712  int brate;
1713  int rmode;
1714  int vmode;
1715  int cmode;
1716  bool forceMono;
1717 
1718  gPrefs->Read(wxT("/FileFormats/MP3Bitrate"), &brate, 128);
1719  gPrefs->Read(wxT("/FileFormats/MP3RateMode"), &rmode, MODE_CBR);
1720  gPrefs->Read(wxT("/FileFormats/MP3VarMode"), &vmode, ROUTINE_FAST);
1721  gPrefs->Read(wxT("/FileFormats/MP3ChannelMode"), &cmode, CHANNEL_STEREO);
1722  gPrefs->Read(wxT("/FileFormats/MP3ForceMono"), &forceMono, 0);
1723 
1724  // Set the bitrate/quality and mode
1725  if (rmode == MODE_SET) {
1726  int q = FindValue(setRates, WXSIZEOF(setRates), brate, PRESET_STANDARD);
1727  int r = FindValue(varModes, WXSIZEOF(varModes), vmode, ROUTINE_FAST);
1728  exporter.SetMode(MODE_SET);
1729  exporter.SetQuality(q, r);
1730  }
1731  else if (rmode == MODE_VBR) {
1732  int q = FindValue(varRates, WXSIZEOF(varRates), brate, QUALITY_2);
1733  int r = FindValue(varModes, WXSIZEOF(varModes), vmode, ROUTINE_FAST);
1734  exporter.SetMode(MODE_VBR);
1735  exporter.SetQuality(q, r);
1736  }
1737  else if (rmode == MODE_ABR) {
1738  bitrate = FindValue(fixRates, WXSIZEOF(fixRates), brate, 128);
1739  exporter.SetMode(MODE_ABR);
1740  exporter.SetBitrate(bitrate);
1741 
1742  if (bitrate > 160) {
1743  lowrate = 32000;
1744  }
1745  else if (bitrate < 32 || bitrate == 144) {
1746  highrate = 24000;
1747  }
1748  }
1749  else {
1750  bitrate = FindValue(fixRates, WXSIZEOF(fixRates), brate, 128);
1751  exporter.SetMode(MODE_CBR);
1752  exporter.SetBitrate(bitrate);
1753 
1754  if (bitrate > 160) {
1755  lowrate = 32000;
1756  }
1757  else if (bitrate < 32 || bitrate == 144) {
1758  highrate = 24000;
1759  }
1760  }
1761 
1762  // Verify sample rate
1763  if (FindName(sampRates, WXSIZEOF(sampRates), rate).IsEmpty() ||
1764  (rate < lowrate) || (rate > highrate)) {
1765  rate = AskResample(bitrate, rate, lowrate, highrate);
1766  if (rate == 0) {
1768  }
1769  }
1770 
1771  // Set the channel mode
1772  if (forceMono) {
1773  exporter.SetChannel(CHANNEL_MONO);
1774  }
1775  else if (cmode == CHANNEL_JOINT) {
1776  exporter.SetChannel(CHANNEL_JOINT);
1777  }
1778  else {
1779  exporter.SetChannel(CHANNEL_STEREO);
1780  }
1781 
1782  auto inSamples = exporter.InitializeStream(channels, rate);
1783  if (((int)inSamples) < 0) {
1784  AudacityMessageBox(_("Unable to initialize MP3 stream"));
1786  }
1787 
1788  // Put ID3 tags at beginning of file
1789  if (metadata == NULL)
1790  metadata = project->GetTags();
1791 
1792  // Open file for writing
1793  wxFFile outFile(fName, wxT("w+b"));
1794  if (!outFile.IsOpened()) {
1795  AudacityMessageBox(_("Unable to open target file for writing"));
1797  }
1798 
1799  ArrayOf<char> id3buffer;
1800  int id3len;
1801  bool endOfFile;
1802  id3len = AddTags(project, id3buffer, &endOfFile, metadata);
1803  if (id3len && !endOfFile) {
1804  outFile.Write(id3buffer.get(), id3len);
1805  }
1806 
1807  wxFileOffset pos = outFile.Tell();
1808  auto updateResult = ProgressResult::Success;
1809  long bytes;
1810 
1811  size_t bufferSize = std::max(0, exporter.GetOutBufferSize());
1812  if (bufferSize == 0)
1814 
1815  ArrayOf<unsigned char> buffer{ bufferSize };
1816  wxASSERT(buffer);
1817 
1818  const WaveTrackConstArray waveTracks =
1819  tracks->GetWaveTrackConstArray(selectionOnly, false);
1820  {
1821  auto mixer = CreateMixer(waveTracks,
1822  tracks->GetTimeTrack(),
1823  t0, t1,
1824  channels, inSamples, true,
1825  rate, int16Sample, true, mixerSpec);
1826 
1827  wxString title;
1828  if (rmode == MODE_SET) {
1829  title.Printf(selectionOnly ?
1830  _("Exporting selected audio with %s preset") :
1831  _("Exporting the audio with %s preset"),
1832  FindName(setRates, WXSIZEOF(setRates), brate));
1833  }
1834  else if (rmode == MODE_VBR) {
1835  title.Printf(selectionOnly ?
1836  _("Exporting selected audio with VBR quality %s") :
1837  _("Exporting the audio with VBR quality %s"),
1838  FindName(varRates, WXSIZEOF(varRates), brate));
1839  }
1840  else {
1841  title.Printf(selectionOnly ?
1842  _("Exporting selected audio at %d Kbps") :
1843  _("Exporting the audio at %d Kbps"),
1844  brate);
1845  }
1846 
1847  ProgressDialog progress(wxFileName(fName).GetName(), title);
1848 
1849  while (updateResult == ProgressResult::Success) {
1850  auto blockLen = mixer->Process(inSamples);
1851 
1852  if (blockLen == 0) {
1853  break;
1854  }
1855 
1856  short *mixed = (short *)mixer->GetBuffer();
1857 
1858  if (blockLen < (unsigned int)inSamples) {
1859  if (channels > 1) {
1860  bytes = exporter.EncodeRemainder(mixed, blockLen, buffer.get());
1861  }
1862  else {
1863  bytes = exporter.EncodeRemainderMono(mixed, blockLen, buffer.get());
1864  }
1865  }
1866  else {
1867  if (channels > 1) {
1868  bytes = exporter.EncodeBuffer(mixed, buffer.get());
1869  }
1870  else {
1871  bytes = exporter.EncodeBufferMono(mixed, buffer.get());
1872  }
1873  }
1874 
1875  if (bytes < 0) {
1876  wxString msg;
1877  msg.Printf(_("Error %ld returned from MP3 encoder"), bytes);
1878  AudacityMessageBox(msg);
1879  updateResult = ProgressResult::Cancelled;
1880  break;
1881  }
1882 
1883  outFile.Write(buffer.get(), bytes);
1884 
1885  updateResult = progress.Update(mixer->MixGetCurrentTime() - t0, t1 - t0);
1886  }
1887  }
1888 
1889  if ( updateResult != ProgressResult::Cancelled ) {
1890  bytes = exporter.FinishStream(buffer.get());
1891 
1892  if (bytes > 0) {
1893  outFile.Write(buffer.get(), bytes);
1894  }
1895 
1896  // Write ID3 tag if it was supposed to be at the end of the file
1897  if (id3len > 0 && endOfFile) {
1898  outFile.Write(id3buffer.get(), id3len);
1899  }
1900 
1901  // Always write the info (Xing/Lame) tag. Until we stop supporting Lame
1902  // versions before 3.98, we must do this after the MP3 file has been
1903  // closed.
1904  //
1905  // Also, if beWriteInfoTag() is used, mGF will no longer be valid after
1906  // this call, so do not use it.
1907  exporter.PutInfoTag(outFile, pos);
1908 
1909  outFile.Close();
1910  }
1911 
1912  return updateResult;
1913 }
int EncodeBuffer(short int inbuffer[], unsigned char outbuffer[])
Definition: ExportMP3.cpp:1328
A list of TrackListNode items.
Definition: Track.h:553
void SetBitrate(int rate)
Definition: ExportMP3.cpp:1055
#define QUALITY_2
Definition: ExportMP3.cpp:119
bool InitLibrary(wxString libpath)
Definition: ExportMP3.cpp:1071
ProgressDialog Class.
bool LoadLibrary(wxWindow *parent, AskUser askuser)
Definition: ExportMP3.cpp:986
#define CHANNEL_JOINT
Definition: ExportMP3.cpp:113
int EncodeRemainder(short int inbuffer[], int nSamples, unsigned char outbuffer[])
Definition: ExportMP3.cpp:1338
#define MODE_VBR
Definition: ExportMP3.cpp:109
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
int InitializeStream(unsigned channels, int sampleRate)
Definition: ExportMP3.cpp:1214
static CHOICES varRates[]
Definition: ExportMP3.cpp:171
bool ValidLibraryLoaded()
Definition: ExportMP3.cpp:1043
std::unique_ptr< Mixer > CreateMixer(const WaveTrackConstArray &inputTracks, const TimeTrack *timeTrack, double startTime, double stopTime, unsigned numOutChannels, size_t outBufferSize, bool outInterleaved, double outRate, sampleFormat outFormat, bool highQuality=true, MixerSpec *mixerSpec=NULL)
Definition: Export.cpp:241
void SetMode(int mode)
Definition: ExportMP3.cpp:1050
TimeTrack * GetTimeTrack()
Definition: Track.cpp:1160
static CHOICES sampRates[]
Definition: ExportMP3.cpp:199
#define PRESET_STANDARD
Definition: ExportMP3.cpp:133
wxFileConfig * gPrefs
Definition: Prefs.cpp:72
WaveTrackConstArray GetWaveTrackConstArray(bool selectionOnly, bool includeMuted=true) const
Definition: Track.cpp:1265
int FindValue(CHOICES *choices, int cnt, int needle, int def)
Definition: ExportMP3.cpp:1921
std::vector< std::shared_ptr< const WaveTrack > > WaveTrackConstArray
Definition: AudioIO.h:65
int EncodeBufferMono(short int inbuffer[], unsigned char outbuffer[])
Definition: ExportMP3.cpp:1349
#define lrint(dbl)
Definition: float_cast.h:136
static CHOICES varModes[]
Definition: ExportMP3.cpp:185
#define MODE_ABR
Definition: ExportMP3.cpp:110
int AddTags(AudacityProject *project, ArrayOf< char > &buffer, bool *endOfFile, const Tags *tags)
Definition: ExportMP3.cpp:2020
#define ROUTINE_FAST
Definition: ExportMP3.cpp:128
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
int EncodeRemainderMono(short int inbuffer[], int nSamples, unsigned char outbuffer[])
Definition: ExportMP3.cpp:1359
#define MODE_SET
Definition: ExportMP3.cpp:108
#define CHANNEL_STEREO
Definition: ExportMP3.cpp:114
#define MODE_CBR
Definition: ExportMP3.cpp:111
void PutInfoTag(wxFFile &f, wxFileOffset off)
Definition: ExportMP3.cpp:1396
int GetOutBufferSize()
Definition: ExportMP3.cpp:1320
static CHOICES setRates[]
Definition: ExportMP3.cpp:191
static CHOICES fixRates[]
Definition: ExportMP3.cpp:148
const Tags * GetTags()
Definition: Project.cpp:1438
void SetQuality(int q, int r)
Definition: ExportMP3.cpp:1060
int AskResample(int bitrate, int rate, int lowrate, int highrate)
Definition: ExportMP3.cpp:1943
void SetChannel(int mode)
Definition: ExportMP3.cpp:1066
double GetRate() const
Definition: Project.h:184
#define CHANNEL_MONO
Definition: ExportMP3.cpp:115
TrackList * GetTracks()
Definition: Project.h:177
wxString FindName(CHOICES *choices, int cnt, int needle)
Definition: ExportMP3.cpp:1932
Class used to export MP3 files.
Definition: ExportMP3.cpp:802
int FinishStream(unsigned char outbuffer[])
Definition: ExportMP3.cpp:1370
wxString ExportMP3::FindName ( CHOICES choices,
int  cnt,
int  needle 
)
private

Definition at line 1932 of file ExportMP3.cpp.

References label, and CHOICES::name.

Referenced by Export().

1933 {
1934  for (int i = 0; i < cnt; i++) {
1935  if (choices[i].label == needle) {
1936  return choices[i].name.BeforeFirst(wxT(','));
1937  }
1938  }
1939 
1940  return wxT("");
1941 }
wxString label
Definition: Tags.cpp:727
wxString name
Definition: ExportMP3.cpp:144
int ExportMP3::FindValue ( CHOICES choices,
int  cnt,
int  needle,
int  def 
)
private

Definition at line 1921 of file ExportMP3.cpp.

References label.

Referenced by Export().

1922 {
1923  for (int i = 0; i < cnt; i++) {
1924  if (choices[i].label == needle) {
1925  return needle;
1926  }
1927  }
1928 
1929  return def;
1930 }
wxString label
Definition: Tags.cpp:727
wxWindow * ExportMP3::OptionsCreate ( wxWindow *  parent,
int  format 
)
overridevirtual

Implements ExportPlugin.

Definition at line 1915 of file ExportMP3.cpp.

References safenew.

1916 {
1917  wxASSERT(parent); // to justify safenew
1918  return safenew ExportMP3Options(parent, format);
1919 }
#define safenew
Definition: Audacity.h:223
int format
Definition: ExportPCM.cpp:56
int ExportMP3::SetNumExportChannels ( )
overrideprivatevirtual

Exporter plug-ins may override this to specify the number of channels in exported file. -1 for unspecified.

Reimplemented from ExportPlugin.

Definition at line 1656 of file ExportMP3.cpp.

References gPrefs.

1657 {
1658  bool mono;
1659  gPrefs->Read(wxT("/FileFormats/MP3ForceMono"), &mono, 0);
1660 
1661  return (mono)? 1 : -1;
1662 }
wxFileConfig * gPrefs
Definition: Prefs.cpp:72

The documentation for this class was generated from the following file: