Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #11 from adct-the-experimenter/add-rm-soundproduce…
Browse files Browse the repository at this point in the history
…rtrack

Add rm soundproducertrack
  • Loading branch information
adct-the-experimenter authored Jul 4, 2019
2 parents 9cfd6ac + 784a6e0 commit 9db3a0f
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 57 deletions.
6 changes: 1 addition & 5 deletions include/osgViewerWX.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,14 @@ 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

void SetViewer(osgViewer::Viewer *viewer);
void SetRootNode(osg::Group* root);
void SetSoundProducerVectorRef(std::vector < std::unique_ptr <SoundProducer> > *sound_producer_vector);
void SetAudioEngineReference(OpenAlSoftAudioEngine* audioEngine);
void SetAudioPlayerReference(OpenALSoftPlayer* audioPlayer);
void SetListenerReference(Listener* listener);

// Mainframe menu operations
Expand Down Expand Up @@ -196,8 +195,6 @@ class MainFrame : public wxFrame

OpenAlSoftAudioEngine* audioEnginePtr;

OpenALSoftPlayer* audioPlayerPtr;

std::vector < std::unique_ptr <SoundProducer> > *sound_producer_vector_ref;

Listener* listenerPtr;
Expand Down Expand Up @@ -244,7 +241,6 @@ class wxOsgApp : public wxApp
std::vector < std::unique_ptr <SoundProducer> > 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> listener;
void initListener();
Expand Down
13 changes: 10 additions & 3 deletions include/soundproducer-track.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion include/soundproducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
47 changes: 18 additions & 29 deletions src/osgViewerWX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand All @@ -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

}
Expand All @@ -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())
Expand Down Expand Up @@ -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) );
Expand Down
27 changes: 16 additions & 11 deletions src/soundproducer-track.cpp
Original file line number Diff line number Diff line change
@@ -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);

Expand Down Expand Up @@ -86,7 +95,7 @@ void SoundProducerTrack::FunctionToCallInNullState()
{
if(soundProducerToManipulatePtr != nullptr)
{
if(*(soundProducerToManipulatePtr->getSource()) != 0)
if(soundProducerToManipulatePtr->getSource() != nullptr)
{
audioTrack->FunctionToCallInNullState();
}
Expand All @@ -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;}
Expand All @@ -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);
}

}
Expand All @@ -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);
Expand Down
18 changes: 11 additions & 7 deletions src/soundproducer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;}
Expand Down
2 changes: 1 addition & 1 deletion src/timeline-track-editor/src/openalsoft-player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9db3a0f

Please sign in to comment.