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

AudioMix Class Reference

Mix the audio with a wav file. More...

Inheritance diagram for AudioMix:

Inheritance graph
[legend]
Collaboration diagram for AudioMix:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 AudioMix ()
virtual ~AudioMix ()
char * GetDescription () const
void Mix (int16_t **io, int16_t **with, int channels, int samples, double mix)
void GetFrame (int16_t **aframe, int frequency, int channels, int &samples, double position, double frame_delta)
void AttachWidgets (GtkBin *bin)
void DetachWidgets (GtkBin *bin)
void InterpretWidgets (GtkBin *bin)
GtkEntry * getEntry () const

Static Public Member Functions

static void on_button_mix_file_clicked (GtkButton *button, gpointer user_data)

Private Attributes

GtkWidget * window
GtkCurve * curve
bool initiated
double offsetSecs
int16_t ** bframe
gfloat m_vector [MAX_VECTOR]

Detailed Description

Mix the audio with a wav file.

NB: To avoid crashes during a preview which starts without audio and then has it switched on midflow, the initiated flag is used to determine that audio is initialised correctly at the start of the effect... This has the unfortunate effect of making audio require a restart in the preview before it is actually played correctly...

Definition at line 458 of file audio_filters.cc.


Constructor & Destructor Documentation

AudioMix::AudioMix  )  [inline]
 

Definition at line 469 of file audio_filters.cc.

References bframe, curve, DV_AUDIO_MAX_SAMPLES, lookup_widget(), magick_glade, on_button_mix_file_clicked(), WavSelect::SetWavFileEntry(), WavSelect::SetWavInfoLabel(), WavSelect::WavFileSelected(), and window.

00469                 : initiated( false )
00470     {
00471         window = glade_xml_get_widget( magick_glade, "window_mix" );
00472         curve = GTK_CURVE( glade_xml_get_widget( magick_glade, "curve_mix" ) );
00473         g_signal_connect( G_OBJECT( lookup_widget( window, "button_mix_file" ) ),
00474             "clicked", G_CALLBACK( on_button_mix_file_clicked ), this );
00475         SetWavInfoLabel( GTK_LABEL( lookup_widget( window, "label_mix_info" ) ) );
00476         SetWavFileEntry( GTK_ENTRY( lookup_widget( window, "entry_mix_file" ) ) );
00477         WavFileSelected();
00478         bframe = new int16_t*[4];
00479         for ( int i = 0; i < 4; i++ )
00480             bframe[i] = new int16_t[ DV_AUDIO_MAX_SAMPLES * 2 ];
00481     }

virtual AudioMix::~AudioMix  )  [inline, virtual]
 

Definition at line 483 of file audio_filters.cc.

References bframe.

00484     {
00485         for ( int i = 0; i < 4; i++ )
00486             delete[] bframe[i];
00487         delete[] bframe;
00488     }


Member Function Documentation

void AudioMix::AttachWidgets GtkBin *  bin  )  [inline, virtual]
 

Reimplemented from GDKAudioFilter.

Definition at line 533 of file audio_filters.cc.

References curve, gtk_curve_reset_vector(), and window.

00534     {
00535         gtk_widget_reparent( ( GTK_BIN( window ) ) ->child, GTK_WIDGET( bin ) );
00536         while ( gtk_events_pending() )
00537             gtk_main_iteration();
00538         gtk_curve_reset_vector( curve, 0.5 );
00539         gtk_curve_set_curve_type( curve, GTK_CURVE_TYPE_LINEAR );
00540     }

void AudioMix::DetachWidgets GtkBin *  bin  )  [inline, virtual]
 

Reimplemented from GDKAudioFilter.

Definition at line 542 of file audio_filters.cc.

References window.

00543     {
00544         gtk_widget_reparent( ( GTK_BIN( bin ) ) ->child, GTK_WIDGET( window ) );
00545     }

char* AudioMix::GetDescription  )  const [inline, virtual]
 

Implements AudioFilter.

Definition at line 490 of file audio_filters.cc.

00491     {
00492         return _( "Mix" );
00493     }

GtkEntry* AudioMix::getEntry  )  const [inline]
 

Definition at line 554 of file audio_filters.cc.

References lookup_widget(), and window.

Referenced by on_button_mix_file_clicked().

00555     {
00556         return GTK_ENTRY( lookup_widget( window, "entry_mix_file" ) );
00557     }

void AudioMix::GetFrame int16_t **  aframe,
int  frequency,
int  channels,
int &  samples,
double  position,
double  frame_delta
[inline, virtual]
 

Implements AudioFilter.

Definition at line 502 of file audio_filters.cc.

References bframe, curve, WavSelect::GetAdjustedSamples(), GetSelectedFramesForFX(), initiated, WavSelect::IsSelected(), m_vector, MAX_VECTOR, Mix(), offsetSecs, WavSelect::WavGetFrequency(), WavSelect::WavRead(), and WavSelect::WavStart().

00503     {
00504         if ( IsSelected() )
00505         {
00506             gtk_curve_get_vector( curve, MAX_VECTOR, m_vector );
00507             if ( !initiated )
00508             {
00509                 initiated = true;
00510                 // nasty approximation (sigh)
00511                 off_t byte_offset = ( int( offsetSecs * WavGetFrequency() )
00512                     + ( GetSelectedFramesForFX().GetIndex( position ) * GetAdjustedSamples( frequency, samples ) ) )
00513                     * channels * 2;
00514                 WavStart( frequency, samples, byte_offset );
00515             }
00516             samples = WavRead( bframe, frequency, channels, samples * channels * 2 );
00517             int pos = int( position * MAX_VECTOR + 0.5 );
00518             Mix( aframe, bframe, channels, samples, m_vector[ pos ] );
00519         }
00520     }

void AudioMix::InterpretWidgets GtkBin *  bin  )  [inline, virtual]
 

Reimplemented from GDKAudioFilter.

Definition at line 547 of file audio_filters.cc.

References initiated, lookup_widget(), offsetSecs, and window.

00548     {
00549         GtkWidget *offsetSpin = lookup_widget( window, "spinbutton_mix_offset" );
00550         offsetSecs = gtk_spin_button_get_value( GTK_SPIN_BUTTON( offsetSpin ) );
00551         initiated = false;
00552     }

void AudioMix::Mix int16_t **  io,
int16_t **  with,
int  channels,
int  samples,
double  mix
[inline]
 

Definition at line 495 of file audio_filters.cc.

Referenced by GetFrame().

00496     {
00497         for ( int s = 0; s < samples; s ++ )
00498             for ( int c = 0; c < channels; c ++ )
00499                 io[ c ][ s ] = ( int16_t ) ( ( double ) io[ c ][ s ] * ( 1.0 - mix ) + ( double ) with[ c ][ s ] * mix );
00500     }

static void AudioMix::on_button_mix_file_clicked GtkButton *  button,
gpointer  user_data
[inline, static]
 

Definition at line 523 of file audio_filters.cc.

References common, getEntry(), and KinoCommon::getFileToOpen().

Referenced by AudioMix().

00524     {
00525         char *filename = common->getFileToOpen( _("Choose an audio file"), false );
00526         if ( filename && strcmp( filename, "" ) )
00527         {
00528             AudioMix *me = static_cast< AudioMix* >( user_data );
00529             gtk_entry_set_text( me->getEntry(), filename );
00530         }
00531     }


Member Data Documentation

int16_t** AudioMix::bframe [private]
 

Definition at line 465 of file audio_filters.cc.

Referenced by AudioMix(), GetFrame(), and ~AudioMix().

GtkCurve* AudioMix::curve [private]
 

Definition at line 462 of file audio_filters.cc.

Referenced by AttachWidgets(), AudioMix(), and GetFrame().

bool AudioMix::initiated [private]
 

Definition at line 463 of file audio_filters.cc.

Referenced by GetFrame(), and InterpretWidgets().

gfloat AudioMix::m_vector[MAX_VECTOR] [private]
 

Definition at line 466 of file audio_filters.cc.

Referenced by GetFrame().

double AudioMix::offsetSecs [private]
 

Definition at line 464 of file audio_filters.cc.

Referenced by GetFrame(), and InterpretWidgets().

GtkWidget* AudioMix::window [private]
 

Definition at line 461 of file audio_filters.cc.

Referenced by AttachWidgets(), AudioMix(), DetachWidgets(), getEntry(), and InterpretWidgets().


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