diff --git a/include/osgViewerWX.h b/include/osgViewerWX.h index 9049a76..d63e05e 100644 --- a/include/osgViewerWX.h +++ b/include/osgViewerWX.h @@ -153,7 +153,7 @@ class MainFrame : public wxFrame { public: MainFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, - const wxSize& size, long style = wxDEFAULT_FRAME_STYLE); + const wxSize& size, OpenAlSoftAudioEngine* thisAudioEngine, long style = wxDEFAULT_FRAME_STYLE); //for connecting mainframe to wxOsgApp @@ -161,7 +161,6 @@ class MainFrame : public wxFrame void SetRootNode(osg::Group* root); void SetSoundProducerVectorRef(std::vector < std::unique_ptr > *sound_producer_vector); void SetAudioEngineReference(OpenAlSoftAudioEngine* audioEngine); - void SetAudioPlayerReference(OpenALSoftPlayer* audioPlayer); void SetListenerReference(Listener* listener); // Mainframe menu operations @@ -196,8 +195,6 @@ class MainFrame : public wxFrame OpenAlSoftAudioEngine* audioEnginePtr; - OpenALSoftPlayer* audioPlayerPtr; - std::vector < std::unique_ptr > *sound_producer_vector_ref; Listener* listenerPtr; @@ -244,7 +241,6 @@ class wxOsgApp : public wxApp std::vector < std::unique_ptr > sound_producer_vector; //vector to hold sound producers OpenAlSoftAudioEngine audio_engine; //class abstraction to handle playing binaural 3D audio - OpenALSoftPlayer* audioPlayer; std::unique_ptr listener; void initListener(); diff --git a/include/soundproducer-track.h b/include/soundproducer-track.h index d33e1f9..33556a4 100644 --- a/include/soundproducer-track.h +++ b/include/soundproducer-track.h @@ -19,14 +19,16 @@ class SoundProducerTrack : public Track { public: - SoundProducerTrack(const wxString& title); + SoundProducerTrack(const wxString& title,ALCdevice* thisAudioDevice,ALCcontext* thisAudioContext); StereoAudioTrack* GetReferenceToStereoAudioTrack(); DoubleTrack* GetReferenceToXTrack(); DoubleTrack* GetReferenceToYTrack(); DoubleTrack* GetReferenceToZTrack(); - void SetReferenceToAudioPlayer(OpenALSoftPlayer* audioPlayer); + //functions to set reference to audio device and audio context to use for player + void SetReferenceToAudioDevice(ALCdevice* thisAudioDevice); + void SetReferenceToAudioContext(ALCcontext* thisAudioContext); //SoundProducer Editing void SetReferenceToSoundProducerToManipulate(SoundProducer* thisSoundProducer); @@ -36,7 +38,9 @@ class SoundProducerTrack : public Track wxComboBox* GetReferenceToComboBox(); + //audio track related functions void SetupAxisForAudio(double& start, double& end,double& resolution, int& numTick); + void SetReferenceToPlaybackControls(PlaybackControls* controls); //Double Track related functions void SetupAxisForVariable(double& start, double& end, double& resolution, int& numTick); @@ -68,7 +72,10 @@ class SoundProducerTrack : public Track private: SoundProducer* soundProducerToManipulatePtr; - OpenALSoftPlayer* audioPlayerPtr; + OpenALSoftPlayer* audioPlayer; + + ALCdevice* audioDevicePtr; //pointer to audio device to be used + ALCcontext* alContextPtr; //pointer to context of where audio is played StereoAudioTrack* audioTrack; DoubleTrack* xTrack; diff --git a/include/soundproducer.h b/include/soundproducer.h index 486cf12..4e29954 100644 --- a/include/soundproducer.h +++ b/include/soundproducer.h @@ -46,7 +46,8 @@ class SoundProducer void setBuffer(ALuint& thisSource); ALuint* getBuffer(); - void CreateSourceFromBuffer(); //function to use openal soft audio engine to create source from buffer + //function to use openal soft audio engine to create source from buffer + void CreateSource(); void setSource(ALuint& thisBuffer); ALuint* getSource(); diff --git a/src/osgViewerWX.cpp b/src/osgViewerWX.cpp index cdeefb6..9b3fafd 100644 --- a/src/osgViewerWX.cpp +++ b/src/osgViewerWX.cpp @@ -22,11 +22,7 @@ bool wxOsgApp::OnInit() else { //initialize audio stuff - audioPlayer = new OpenALSoftPlayer(); - audioPlayer->SetReferenceToAudioContext(audio_engine.GetReferenceToAudioContext()); - audioPlayer->SetReferenceToAudioDevice(audio_engine.GetReferenceToAudioDevice()); - - audioPlayer->InitBuffersForStreaming(); + //initialize graphical stuff int width = 800; @@ -35,10 +31,7 @@ bool wxOsgApp::OnInit() // Create the main frame window MainFrame *frame = new MainFrame(NULL, wxT("Binaural Audio Editor"), - wxDefaultPosition, wxSize(width, height)); - - //set reference to audio player. IMPORTANT - frame->SetAudioPlayerReference(audioPlayer); + wxDefaultPosition, wxSize(width, height),&audio_engine); // create osg canvas // - initialize @@ -155,9 +148,11 @@ END_EVENT_TABLE() /* My frame constructor */ MainFrame::MainFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, - const wxSize& size, long style) + const wxSize& size, OpenAlSoftAudioEngine* thisAudioEngine,long style) : wxFrame(frame, wxID_ANY, title, pos, size, style) { + MainFrame::SetAudioEngineReference(thisAudioEngine); + //create file menu item wxMenu *menuFile = new wxMenu; menuFile->Append(wxID_EXIT); @@ -203,7 +198,11 @@ MainFrame::MainFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, timeFrame = new TimelineFrame(this); - m_soundproducer_track_vec.push_back(new SoundProducerTrack("SoundProducer Track")); + m_soundproducer_track_vec.push_back(new SoundProducerTrack("SoundProducer Track", + audioEnginePtr->GetReferenceToAudioDevice(), + audioEnginePtr->GetReferenceToAudioContext()) + ); + m_listener_track = new ListenerTrack("Listener Track"); int space = 20; //the distance,in pixels, between track and previous item(timeline or previous track) @@ -247,6 +246,7 @@ MainFrame::MainFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, wxButton* browseButton = new wxButton(timeFrame->GetTimelineWindow(), wxID_ANY, wxT("Browse"), wxDefaultPosition, wxSize(70, 30) ); m_soundproducer_track_vec[0]->GetReferenceToStereoAudioTrack()->SetReferenceToBrowseButton(browseButton); m_soundproducer_track_vec[0]->GetReferenceToStereoAudioTrack()->InitTrack(timeFrame->GetTimelineWindow(),nullptr); + m_soundproducer_track_vec.at(0)->SetReferenceToPlaybackControls(timeFrame->GetPlaybackControlsReference()); //initialize double tracks m_soundproducer_track_vec[0]->SetupAxisForVariable(start,end,resolution,numTicks); //setup bounds for vertical axes @@ -303,7 +303,7 @@ MainFrame::MainFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, m_add_soundproducertrack_button = new wxButton(timeFrame->GetTimelineWindow(), wxID_ANY, wxT("Add SoundProducer Track"), wxDefaultPosition, wxSize(200, 30) ); m_add_soundproducertrack_button->Bind(wxEVT_BUTTON, &MainFrame::OnAddSoundProducerTrack,this); - /* + m_remove_soundproducertrack_button = new wxButton(timeFrame->GetTimelineWindow(), wxID_ANY, wxT("Remove SoundProducer Track"), wxDefaultPosition, wxSize(200, 30) ); m_remove_soundproducertrack_button->Bind(wxEVT_BUTTON, &MainFrame::OnRemoveSoundProducerTrack,this); @@ -314,7 +314,7 @@ MainFrame::MainFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, m_add_rm_box_sizer->Add(m_add_soundproducertrack_button); timeFrame->AddBoxSizer(m_add_rm_box_sizer); - */ + timeFrame->Show(true); //show the timeframe } @@ -338,16 +338,6 @@ void MainFrame::SetListenerReference(Listener* thisListener) void MainFrame::SetAudioEngineReference(OpenAlSoftAudioEngine* audioEngine){ audioEnginePtr = audioEngine;} -void MainFrame::SetAudioPlayerReference(OpenALSoftPlayer* audioPlayer) -{ - audioPlayerPtr = audioPlayer; - //for all sound producer tracks - for(size_t i=0; i < m_soundproducer_track_vec.size(); i++) - { - m_soundproducer_track_vec[i]->SetReferenceToAudioPlayer(audioPlayerPtr); - } -} - void MainFrame::OnIdle(wxIdleEvent &event) { if (!_viewer->isRealized()) @@ -514,15 +504,14 @@ void MainFrame::CreateNewSoundProducerTrack() wxString title = wxString("SoundProducer Track " + result); - m_soundproducer_track_vec.push_back(new SoundProducerTrack("SoundProducer Track")); + m_soundproducer_track_vec.push_back(new SoundProducerTrack("SoundProducer Track", + audioEnginePtr->GetReferenceToAudioDevice(), + audioEnginePtr->GetReferenceToAudioContext()) + ); - //set reference to audio player - if(audioPlayerPtr != nullptr) - { - m_soundproducer_track_vec.at(m_soundproducer_track_vec.size()-1)->SetReferenceToAudioPlayer(audioPlayerPtr); - } //initialize sound producer track stuff m_soundproducer_track_vec.at(m_soundproducer_track_vec.size()-1)->InitTrack(timeFrame->GetTimelineWindow(),nullptr); + m_soundproducer_track_vec.at(m_soundproducer_track_vec.size()-1)->SetReferenceToPlaybackControls(timeFrame->GetPlaybackControlsReference()); //initialize audio track wxButton* browseButton = new wxButton(timeFrame->GetTimelineWindow(), wxID_ANY, wxT("Browse"), wxDefaultPosition, wxSize(70, 30) ); diff --git a/src/soundproducer-track.cpp b/src/soundproducer-track.cpp index 3be5ebb..0ebaa99 100644 --- a/src/soundproducer-track.cpp +++ b/src/soundproducer-track.cpp @@ -1,16 +1,25 @@ #include "soundproducer-track.h" -SoundProducerTrack::SoundProducerTrack(const wxString& title) : Track(title) +SoundProducerTrack::SoundProducerTrack(const wxString& title,ALCdevice* thisAudioDevice,ALCcontext* thisAudioContext) : Track(title) { soundProducerToManipulatePtr = nullptr; m_combo_box = nullptr; + //initialize audio player + audioPlayer = new OpenALSoftPlayer(); + audioPlayer->SetReferenceToAudioContext(thisAudioContext); + audioPlayer->SetReferenceToAudioDevice(thisAudioDevice); + + audioPlayer->InitBuffersForStreaming(); + //initialize tracks xTrack = new DoubleTrack("X Track"); yTrack = new DoubleTrack("Y Track"); zTrack = new DoubleTrack("Z Track"); audioTrack = new StereoAudioTrack("Track"); + audioTrack->SetReferenceToAudioPlayer(audioPlayer); + std::string filepath_stream = "../src/timeline-track-editor/resources/" + title.ToStdString() + ".wav"; audioTrack->SetStreamAudioFilePath(filepath_stream); @@ -86,7 +95,7 @@ void SoundProducerTrack::FunctionToCallInNullState() { if(soundProducerToManipulatePtr != nullptr) { - if(*(soundProducerToManipulatePtr->getSource()) != 0) + if(soundProducerToManipulatePtr->getSource() != nullptr) { audioTrack->FunctionToCallInNullState(); } @@ -100,12 +109,6 @@ void SoundProducerTrack::SetReferenceToSoundProducerToManipulate(SoundProducer* audioTrack->SetReferenceToSourceToManipulate(soundProducerToManipulatePtr->getSource()); } -void SoundProducerTrack::SetReferenceToAudioPlayer(OpenALSoftPlayer* audioPlayer) -{ - audioPlayerPtr = audioPlayer; - audioTrack->SetReferenceToAudioPlayer(audioPlayer); -} - StereoAudioTrack* SoundProducerTrack::GetReferenceToStereoAudioTrack(){return audioTrack;} DoubleTrack* SoundProducerTrack::GetReferenceToXTrack(){return xTrack;} DoubleTrack* SoundProducerTrack::GetReferenceToYTrack(){return yTrack;} @@ -132,9 +135,6 @@ void SoundProducerTrack::OnSelectedSoundProducerInComboBox(wxCommandEvent& event SoundProducer* thisSoundProducer = soundproducer_registry_ptr->GetPointerToSoundProducerWithThisName(thisStringName); SoundProducerTrack::SetReferenceToSoundProducerToManipulate(thisSoundProducer); - - //remove name from list of sound producers to edit and update combobox list - soundproducer_registry_ptr->RemoveThisNameFromAllComboBoxesExceptThisOne(thisStringName,m_combo_box); } } @@ -160,6 +160,11 @@ void SoundProducerTrack::SetupAxisForAudio(double& start, double& end,double& re audioTrack->SetupAxisForVariable(start,end,resolution,numTick); } +void SoundProducerTrack::SetReferenceToPlaybackControls(PlaybackControls* controls) +{ + audioTrack->SetReferenceToPlaybackControls(controls); +} + void SoundProducerTrack::OnPaint(wxPaintEvent& event) { wxPaintDC dc(this); diff --git a/src/soundproducer.cpp b/src/soundproducer.cpp index c020cda..c405394 100644 --- a/src/soundproducer.cpp +++ b/src/soundproducer.cpp @@ -2,15 +2,19 @@ SoundProducer::SoundProducer() { + //intialize source + SoundProducer::CreateSource(); + + //initialize buffer as empty m_buffer = 0; - m_source = 0; + //initialize position vector producer_position_vector.resize(3); producer_position_vector[POSITION_INDEX::X] = 0; producer_position_vector[POSITION_INDEX::Y] = 0; producer_position_vector[POSITION_INDEX::Z] = 0; - + } SoundProducer::~SoundProducer() @@ -44,8 +48,10 @@ void SoundProducer::InitSoundProducer(std::string& thisName,std::string& filepat name = thisName; m_filepath = filepath; - m_buffer = buffer; - SoundProducer::CreateSourceFromBuffer(); + if(buffer != 0) + { + SoundProducer::setBuffer(buffer); + } //set position producer_position_vector[POSITION_INDEX::X] = x; @@ -147,14 +153,12 @@ void SoundProducer::setBuffer(ALuint& thisBuffer) } ALuint* SoundProducer::getBuffer(){return &m_buffer;} -void SoundProducer::CreateSourceFromBuffer() +void SoundProducer::CreateSource() { alGenSources(1, &m_source); alSourcei(m_source, AL_SOURCE_RELATIVE, AL_TRUE); - alSourcei(m_source, AL_BUFFER, m_buffer); assert(alGetError()==AL_NO_ERROR && "Failed to setup sound source."); - moveSource(); //move source to proper location based on current position vector } void SoundProducer::setSource(ALuint& thisSource){m_source = thisSource;} diff --git a/src/timeline-track-editor/src/openalsoft-player.cpp b/src/timeline-track-editor/src/openalsoft-player.cpp index 9f23d4c..d1e24ee 100644 --- a/src/timeline-track-editor/src/openalsoft-player.cpp +++ b/src/timeline-track-editor/src/openalsoft-player.cpp @@ -226,7 +226,7 @@ int OpenALSoftPlayer::StartPlayer(ALuint* source, double& current_time) //std::cout << "In start player!\n"; size_t i; - + /* Rewind the source position and clear the buffer queue */ alSourceRewind(*source); alSourcei(*source, AL_BUFFER, 0);