Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ExportAudio Class Reference

This class represents the Export/Still Frames notebook page. More...

#include <page_export_audio.h>

Inheritance diagram for ExportAudio:

Inheritance graph
[legend]
Collaboration diagram for ExportAudio:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ExportAudio (PageExport *, KinoCommon *)
 Constructor for page.
virtual ~ExportAudio ()
 Destructor for page.

Private Member Functions

enum export_result doExport (PlayList *playlist, int begin, int end, int every, bool preview)
 start exporting audio

Private Attributes

GtkEntry * fileEntry
GtkMenu * sampleRate
GtkMenu * audioFormat
GtkToggleButton * splitCheck

Detailed Description

This class represents the Export/Still Frames notebook page.

Definition at line 33 of file page_export_audio.h.


Constructor & Destructor Documentation

ExportAudio::ExportAudio PageExport _exportPage,
KinoCommon _common
 

Constructor for page.

Parameters:
common common object to which this page belongs

Definition at line 48 of file page_export_audio.cc.

References audioFormat, Export::common, Export::exportPage, fileEntry, PageExport::getWidget(), KinoCommon::getWidget(), lookup_widget(), sampleRate, and splitCheck.

00048                                                                        :
00049         Export( _exportPage, _common )
00050 {
00051     cerr << "> Creating ExportAudio Page" << endl;
00052     fileEntry = GTK_ENTRY( lookup_widget( common->getWidget(), "entry_export_audio_file" ) );
00053 
00054     sampleRate
00055     = GTK_MENU( gtk_option_menu_get_menu( GTK_OPTION_MENU( lookup_widget( exportPage->getWidget(),
00056                                           "optionmenu_export_audio_sampling" ) ) ) );
00057     audioFormat
00058     = GTK_MENU( gtk_option_menu_get_menu( GTK_OPTION_MENU( lookup_widget( exportPage->getWidget(),
00059                                           "optionmenu_export_audio_format" ) ) ) );
00060     splitCheck
00061     = GTK_TOGGLE_BUTTON( lookup_widget( exportPage->getWidget(),
00062                                         "checkbutton_export_audio_split" ) );
00063 }

ExportAudio::~ExportAudio  )  [virtual]
 

Destructor for page.

Definition at line 68 of file page_export_audio.cc.

00069 {
00070     cerr << "> Destroying ExportAudio Page" << endl;
00071 }


Member Function Documentation

enum export_result ExportAudio::doExport PlayList playlist,
int  begin,
int  end,
int  every,
bool  preview
[private, virtual]
 

start exporting audio

Implements Export.

Definition at line 76 of file page_export_audio.cc.

References AUDIO_RESAMPLE_SRC_SINC_BEST_QUALITY, audioFormat, Export::calculateAdjustedRate(), KinoAudioPipe::CloseAudio(), KinoAudioFactory::CreateAudioPipe(), EXPORT_RESULT_ABORT, EXPORT_RESULT_FAILURE, EXPORT_RESULT_SUCCESS, Export::exportPage, fileEntry, PlayList::FindEndOfScene(), Frame::GetAudioInfo(), AsyncAudioResample< input_t, output_t >::GetError(), PlayList::GetFrame(), GetFramePool(), AsyncAudioResample< input_t, output_t >::GetOutput(), info, Export::innerLoopUpdate(), AsyncAudioResample< input_t, output_t >::IsError(), PageExport::isExporting, modal_message(), KinoAudioPipe::OpenAudio(), KinoAudioPipe::OutputAudioFrame(), PIPE_AUDIO_PCM, PIPE_AUDIO_WAV, AsyncAudioResample< input_t, output_t >::Process(), sampleRate, and splitCheck.

00078 {
00079     cerr << ">>> ExportAudio::doExport" << endl;
00080     Frame& frame = *GetFramePool()->GetFrame();
00081     gchar *file = NULL;
00082     enum export_result status = EXPORT_RESULT_SUCCESS;
00083 
00084     /* Check the filename */
00085     file = g_strdup( gtk_entry_get_text( fileEntry ) );
00086     if ( !( strcmp( file, "" ) && strpbrk( file, "\'" ) == NULL ) )
00087     {
00088         modal_message( _( "You must enter a filename which does not contain quotes." ) );
00089         g_free( file );
00090         return EXPORT_RESULT_FAILURE;
00091     }
00092 
00093 
00094     // Get a sample frame to obtain recording info
00095     playlist->GetFrame( begin, frame );
00096 
00097     AudioInfo info;
00098     frame.GetAudioInfo( info );
00099     short channels = info.channels;
00100     int outputFrequency = info.frequency;
00101     bool splitScene = gtk_toggle_button_get_active( splitCheck );
00102 
00103     // Determine requested output frequency
00104     GtkWidget *active_item = gtk_menu_get_active( sampleRate );
00105     int menuValue = g_list_index ( GTK_MENU_SHELL ( sampleRate ) ->children,
00106                                    active_item );
00107     if ( menuValue == 1 )
00108         outputFrequency = 32000;
00109     else if ( menuValue == 2 )
00110         outputFrequency = 44100;
00111     else if ( menuValue == 3 )
00112         outputFrequency = 48000;
00113 
00114     // Determine the output format
00115     active_item = gtk_menu_get_active( audioFormat );
00116     menuValue = g_list_index ( GTK_MENU_SHELL ( audioFormat ) ->children, active_item );
00117 
00118     gchar *outputtemplate = NULL;
00119     kino_audio_pipe type = PIPE_AUDIO_WAV;
00120 
00121     if ( menuValue == 0 )
00122     {
00123         outputtemplate = g_strdup_printf( "%s%%s.wav", file );
00124         type = PIPE_AUDIO_WAV;
00125     }
00126     else if ( menuValue == 1 )
00127     {
00128         outputtemplate = g_strdup_printf( "| sox -t .raw -r %d -c 2 -w -s - \'%s\'%%s.wav",
00129                  outputFrequency, file );
00130         type = PIPE_AUDIO_WAV;
00131     }
00132     else if ( menuValue == 2 )
00133     {
00134         outputtemplate = g_strdup_printf( "| mp2enc -r %d -o \'%s\'%%s.mp2",
00135                  outputFrequency, file );
00136         type = PIPE_AUDIO_WAV;
00137     }
00138     else if ( menuValue == 3 )
00139     {
00140         outputtemplate = g_strdup_printf( "| lame -r -s %d -x - -o \'%s\'%%s.mp3",
00141                  outputFrequency / 1000, file );
00142         type = PIPE_AUDIO_PCM;
00143     }
00144     else if ( menuValue == 4 )
00145     {
00146         outputtemplate = g_strdup_printf( "| oggenc - -o \'%s\'%%s.ogg", file );
00147         type = PIPE_AUDIO_WAV;
00148     }
00149 
00150     // Iterate through each scene (opening and closing audio pipes as requested)
00151     KinoAudioPipe *outputPipe = KinoAudioFactory::CreateAudioPipe( type );
00152     int scene = 0;
00153     for ( int sceneBegin = begin; sceneBegin <= end && exportPage->isExporting;
00154             scene ++ )
00155     {
00156         gchar *full;
00157         char sceneString[ 5 ];
00158         int sceneEnd = end;
00159 
00160         // Determine if we need to split by scene or not
00161         if ( splitScene )
00162         {
00163             sprintf( sceneString, "%03d", scene );
00164             sceneEnd = playlist->FindEndOfScene( sceneBegin );
00165             if ( sceneEnd > end )
00166                 sceneEnd = end;
00167         }
00168         else
00169         {
00170             strcpy( sceneString, "" );
00171         }
00172 
00173         // expand the template to accomodate the scene splits
00174         full = g_strdup_printf( outputtemplate, sceneString );
00175 
00176         // output this scene
00177         bool active = outputPipe->OpenAudio( full, channels, outputFrequency, 2 );
00178         g_free( full );
00179         
00180         if ( active )
00181         {
00182             // Call this before hand to initialise the counters
00183             // calculateAdjustedRate will accumulate time as paused time to prevent
00184             // distorting the estimate.
00185             innerLoopUpdate( sceneBegin, begin, end, every );
00186 
00187             // Determine correct amount of audio for duration
00188             double adjustedRate = calculateAdjustedRate( playlist, outputFrequency, sceneBegin, sceneEnd, every );
00189             if ( ! adjustedRate )
00190                 status = EXPORT_RESULT_ABORT;
00191 
00192             // Setup a resampler
00193             AsyncAudioResample<int16_ne_t,int16_le_t>* resampler = new AsyncAudioResample<int16_ne_t,int16_le_t>(
00194                 AUDIO_RESAMPLE_SRC_SINC_BEST_QUALITY, playlist, outputFrequency, sceneBegin, sceneEnd, every );
00195             if ( resampler->IsError() )
00196             {
00197                 std::cerr << ">>> Resampler error: " << resampler->GetError() << std::endl;
00198                 exportPage->isExporting = false;
00199                 status = EXPORT_RESULT_FAILURE;
00200                 break;
00201             }
00202 
00203             // Now run through the frames in this scene
00204             for ( int i = sceneBegin, j = 0; i <= sceneEnd && exportPage->isExporting;
00205                     i += every, j++ )
00206             {
00207                 innerLoopUpdate( i, begin, end, every );
00208 
00209                 int requestedSamples = frame.CalculateNumberSamples( outputFrequency, j );
00210                 int nsamples = resampler->Process( adjustedRate, requestedSamples );
00211                 if ( nsamples > 0 && !outputPipe->OutputAudioFrame( (int16_t *)resampler->GetOutput(), nsamples * channels * sizeof(int16_t) ) )
00212                 {
00213                     modal_message( _( "Error during audio export - aborting." ) );
00214                     status = EXPORT_RESULT_FAILURE;
00215                     exportPage->isExporting = false;
00216                 }
00217             }
00218             if ( status == EXPORT_RESULT_SUCCESS && !exportPage->isExporting )
00219                 status = EXPORT_RESULT_ABORT;
00220             
00221             // Cleanup
00222             outputPipe->CloseAudio();
00223             delete resampler;
00224             resampler = 0;
00225         }
00226         else
00227         {
00228             modal_message( _( "Error starting output" ) );
00229             status = EXPORT_RESULT_FAILURE;
00230             break;
00231         }
00232 
00233         // Move to start of next scene
00234         sceneBegin = sceneEnd + 1;
00235     }
00236 
00237     g_free( file );
00238     g_free( outputtemplate );
00239     delete outputPipe;
00240 
00241     GetFramePool()->DoneWithFrame( &frame );
00242     
00243     return status;
00244 }


Member Data Documentation

GtkMenu* ExportAudio::audioFormat [private]
 

Definition at line 39 of file page_export_audio.h.

Referenced by doExport(), and ExportAudio().

GtkEntry* ExportAudio::fileEntry [private]
 

Definition at line 37 of file page_export_audio.h.

Referenced by doExport(), and ExportAudio().

GtkMenu* ExportAudio::sampleRate [private]
 

Definition at line 38 of file page_export_audio.h.

Referenced by doExport(), and ExportAudio().

GtkToggleButton* ExportAudio::splitCheck [private]
 

Definition at line 40 of file page_export_audio.h.

Referenced by doExport(), and ExportAudio().


The documentation for this class was generated from the following files:
Generated on Sun Mar 11 22:12:51 2007 for Kino by  doxygen 1.4.2