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 #30 from adct-the-experimenter/DAW_plugin_use
Browse files Browse the repository at this point in the history
Daw plugin use
  • Loading branch information
adct-the-experimenter authored Dec 18, 2019
2 parents a3e96c1 + 9172f0a commit 5f8afe0
Show file tree
Hide file tree
Showing 16 changed files with 224 additions and 73 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,12 @@ OpenAL Soft should automatically convert 3d audio information into audio output

For more information, read https://github.com/kcat/openal-soft/blob/master/docs/3D7.1.txt

## To use with Digital Audio Workstation

See the import-audio-DAW-BAE plugin page about building and installing the plugin.

https://github.com/adct-the-experimenter/import-audio-DAW-BAE

This plugin will export audio from a digital audio workstation to the sound tracks of binaural audio editor so that one can use their DAW to edit audio and spatialize it in Binaural Audio Editor.
## Feedback
Please email questions or comments to this email address bringerofawesomefood @ gmail . com without spaces.
2 changes: 1 addition & 1 deletion include/soundproducer-track-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SoundProducerTrackManager : public Track

bool soundPlaying;
void SetSoundPlayingBool(bool status);

};

#endif
9 changes: 9 additions & 0 deletions include/soundproducer-track.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class SoundProducerTrack : public Track
bool IsReverbApplied();
void SetStatusReverbApplied(bool status);

//Audio DAW
void SetReferenceToImportAudioDAWButton(wxButton* thisButton);

private:
SoundProducer* soundProducerToManipulatePtr;

Expand Down Expand Up @@ -106,6 +109,12 @@ class SoundProducerTrack : public Track
//bool to tell if reverb is applied to the source of the track
bool reverbApplied;

//button for using the DAW audio import plugin for binaural audio editor
wxButton* m_importAudioDAWButton;

void OnImportAudioDAWButtonClick(wxCommandEvent& event);

std::string streamSoundFilePath;
};

#endif
21 changes: 13 additions & 8 deletions src/osgViewerWX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,12 @@ MainFrame::MainFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
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());


wxButton* importAudioDAWButton = new wxButton(timeFrame->GetTimelineWindow(), wxID_ANY, wxT("Import DAW Audio"), wxDefaultPosition, wxSize(150, 30) );
m_soundproducer_track_vec.at(0)->SetReferenceToImportAudioDAWButton(importAudioDAWButton);



//initialize double tracks
m_soundproducer_track_vec[0]->SetupAxisForVariable(start,end,resolution,numTicks); //setup bounds for vertical axes
m_soundproducer_track_vec[0]->SetReferenceToSoundProducerRegistry(&soundproducer_registry);
Expand Down Expand Up @@ -543,6 +548,7 @@ MainFrame::MainFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
wxStaticText *textButtonText = new wxStaticText(timeFrame->GetTimelineWindow(), wxID_ANY, wxT("Stereo Audio Track"),wxDefaultPosition );
hboxButtonText->Add(textButtonText);
hboxButtonText->Add(browseButton);
hboxButtonText->Add(importAudioDAWButton);
timeFrame->AddBoxSizer(hboxButtonText);

//add label for left channel audio
Expand All @@ -563,6 +569,7 @@ MainFrame::MainFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
//add right channel track to time frame
timeFrame->AddTrack(m_soundproducer_track_vec[0]->GetReferenceToStereoAudioTrack()->GetReferenceToRightChannelTrack(),space);

//add track functions to call for sound producer track manager
timeFrame->AddTrackFunctionToCallInTimerLoopPlayState(soundproducertrack_manager_ptr.get());
timeFrame->AddTrackFunctionToCallInTimerLoopNullState(soundproducertrack_manager_ptr.get());
timeFrame->AddTrackFunctionToCallInTimerLoopPauseState(soundproducertrack_manager_ptr.get());
Expand Down Expand Up @@ -905,7 +912,10 @@ void MainFrame::CreateNewSoundProducerTrack()
wxButton* browseButton = new wxButton(timeFrame->GetTimelineWindow(), wxID_ANY, wxT("Browse"), wxDefaultPosition, wxSize(70, 30) );
m_soundproducer_track_vec.at(m_soundproducer_track_vec.size()-1)->GetReferenceToStereoAudioTrack()->SetReferenceToBrowseButton(browseButton);
m_soundproducer_track_vec.at(m_soundproducer_track_vec.size()-1)->GetReferenceToStereoAudioTrack()->InitTrack(timeFrame->GetTimelineWindow(),nullptr);


wxButton* importAudioDAWButton = new wxButton(timeFrame->GetTimelineWindow(), wxID_ANY, wxT("Import DAW Audio"), wxDefaultPosition, wxSize(150, 30) );
m_soundproducer_track_vec.at(m_soundproducer_track_vec.size()-1)->SetReferenceToImportAudioDAWButton(importAudioDAWButton);

//initialize double tracks

int space = 20; //the distance,in pixels, between track and previous item(timeline or previous track)
Expand Down Expand Up @@ -943,6 +953,7 @@ void MainFrame::CreateNewSoundProducerTrack()
wxStaticText *textButtonText = new wxStaticText(timeFrame->GetTimelineWindow(), wxID_ANY, wxT("Stereo Audio Track"),wxDefaultPosition );
hboxButtonText->Add(textButtonText);
hboxButtonText->Add(browseButton);
hboxButtonText->Add(importAudioDAWButton);
timeFrame->AddBoxSizer(hboxButtonText);

//add label for left channel audio
Expand All @@ -963,12 +974,6 @@ void MainFrame::CreateNewSoundProducerTrack()
//add right channel track to time frame
timeFrame->AddTrack(m_soundproducer_track_vec.at(m_soundproducer_track_vec.size()-1)->GetReferenceToStereoAudioTrack()->GetReferenceToRightChannelTrack(),space);

//timeFrame->AddTrackFunctionToCallInTimerLoopPlayState(m_soundproducer_track_vec.at(m_soundproducer_track_vec.size()-1));
//timeFrame->AddTrackFunctionToCallInTimerLoopNullState(m_soundproducer_track_vec.at(m_soundproducer_track_vec.size()-1));
//timeFrame->AddTrackFunctionToCallInTimerLoopPauseState(m_soundproducer_track_vec.at(m_soundproducer_track_vec.size()-1));
//timeFrame->AddTrackFunctionToCallInTimerLoopRewindState(m_soundproducer_track_vec.at(m_soundproducer_track_vec.size()-1));
//timeFrame->AddTrackFunctionToCallInTimerLoopFastForwardState(m_soundproducer_track_vec.at(m_soundproducer_track_vec.size()-1));

//add x,y,z tracks of SoundProducerTrack to time frame

//add label for x track
Expand Down
69 changes: 69 additions & 0 deletions src/soundproducer-track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ SoundProducerTrack::SoundProducerTrack(const wxString& title,ALCdevice* thisAudi
soundProducerToManipulatePtr = nullptr;
m_combo_box = nullptr;

m_importAudioDAWButton = nullptr;

//initialize audio player
audioPlayer = new OpenALSoftPlayer();
audioPlayer->SetReferenceToAudioContext(thisAudioContext);
Expand All @@ -32,6 +34,7 @@ SoundProducerTrack::SoundProducerTrack(const wxString& title,ALCdevice* thisAudi

std::string filepath_stream = "../src/timeline-track-editor/resources/" + title.ToStdString() + ".wav";
audioTrack->SetStreamAudioFilePath(filepath_stream);
streamSoundFilePath = filepath_stream;

tempX=0.0; tempY=0.0; tempZ=0.0;

Expand Down Expand Up @@ -291,3 +294,69 @@ SoundProducer* SoundProducerTrack::GetReferenceToSoundProducerManipulated(){retu
bool SoundProducerTrack::IsReverbApplied(){return reverbApplied;}

void SoundProducerTrack::SetStatusReverbApplied(bool status){reverbApplied = status;}


void SoundProducerTrack::SetReferenceToImportAudioDAWButton(wxButton* thisButton)
{
m_importAudioDAWButton = thisButton;

m_importAudioDAWButton->Bind(wxEVT_BUTTON, &SoundProducerTrack::OnImportAudioDAWButtonClick,this);
}

void SoundProducerTrack::OnImportAudioDAWButtonClick(wxCommandEvent& event)
{
//clear graphs
audioTrack->GetReferenceToLeftChannelTrack()->ClearGraph();
audioTrack->GetReferenceToRightChannelTrack()->ClearGraph();

std::cout << "Importing audio from DAW...\n";

//load audio file imported_audio_DAW.wav
//use this path in your app
std::string inputSoundFilePath = std::string("../src/timeline-track-editor/resources/") + std::string("imported_audio_DAW.wav");

SF_INFO input_sfinfo;

int channels = audioTrack->GetReferenceToLeftChannelTrack()->GetNumberOfChannelsInAudioFile(inputSoundFilePath,input_sfinfo);
std::cout << "channels:" << channels << std::endl;

if(channels == 0)
{
wxMessageBox(wxT("Failed to load audio from imported_audio_DAW.wav!\n No such file or data is incorrect. \n"));
}

//object to hold audio data for streaming
AudioStreamContainer audio_data_stream;

//Hold data for left channel and right channel
std::vector <double> audio_data_input_copy;

if(channels == 1)
{
//create a copy of file to reference for editing
//also put data into stream
audioTrack->GetReferenceToLeftChannelTrack()->ReadAndCopyDataFromInputFile(&audio_data_input_copy,inputSoundFilePath,input_sfinfo);
audioTrack->GetReferenceToLeftChannelTrack()->CopyInputDataIntoAudioDataStream(&audio_data_input_copy,&audio_data_stream,streamSoundFilePath,input_sfinfo);
//graph all data in channel to one graph
audioTrack->GetReferenceToLeftChannelTrack()->PlotOneChannelStreamAudioDataToGraph(&audio_data_stream,input_sfinfo);
}
else if(channels == 2)
{
//create a copy of file to reference for editing
//also put data into stream
audioTrack->GetReferenceToLeftChannelTrack()->ReadAndCopyDataFromInputFile(&audio_data_input_copy,inputSoundFilePath,input_sfinfo);
audioTrack->GetReferenceToLeftChannelTrack()->CopyInputDataIntoAudioDataStream(&audio_data_input_copy,&audio_data_stream,streamSoundFilePath,input_sfinfo);

//plot left channel data to one graph
audioTrack->GetReferenceToLeftChannelTrack()->PlotLeftChannelStreamAudioDataToGraph(&audio_data_stream,input_sfinfo);
//plot right channel data to other graph
audioTrack->GetReferenceToRightChannelTrack()->PlotRightChannelStreamAudioDataToGraph(&audio_data_stream,input_sfinfo);

}

//open file to play during streaming
audioPlayer->OpenPlayerFile(streamSoundFilePath.c_str());

std::cout << "\nFinished importing audio from DAW!\n";
event.Skip();
}
2 changes: 2 additions & 0 deletions src/timeline-track-editor/include/audio-graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class AudioGraph : public wxPanel

void PlotAudioDataToGraph(std::vector <double> *audio_data, int sample_rate, double& verticalStart, double& verticalEnd, double& verticalResolution);

void ClearGraph();

private:

std::vector <int> *timeTickVectorPtr;
Expand Down
3 changes: 3 additions & 0 deletions src/timeline-track-editor/include/audio-stream-container.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class AudioStreamContainer
int GetChannels();
int GetSampleRate();

void ClearStreamDataStored();
void ClearDataInStreamFile(std::string filename);

private:
std::vector <double> *input_audio_data_ptr;

Expand Down
2 changes: 2 additions & 0 deletions src/timeline-track-editor/include/audio-track.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class AudioTrack : public Track
void SetAudioTrackState(int thisState);
int GetAudioTrackState();

void ClearGraph();

private:

//Audio Processes and Operations
Expand Down
7 changes: 0 additions & 7 deletions src/timeline-track-editor/include/mono-audio-track.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,6 @@ class MonoAudioTrack : public Track
void logic_right_click();

private:
//object to hold audio data for streaming
AudioStreamContainer audio_data_stream;

//Hold data for left channel and right channel
std::vector <double> audio_data_input_copy;

SF_INFO input_sfinfo;

AudioTrack* m_channel_track;

Expand Down
7 changes: 0 additions & 7 deletions src/timeline-track-editor/include/stereo-audio-track.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@ class StereoAudioTrack : public Track
void logic_right_click();

private:
//object to hold audio data for streaming
AudioStreamContainer audio_data_stream;

//Hold data for left channel and right channel
std::vector <double> audio_data_input_copy;

SF_INFO input_sfinfo;

AudioTrack* m_left_channel_track;
AudioTrack* m_right_channel_track;
Expand Down
6 changes: 6 additions & 0 deletions src/timeline-track-editor/src/audio-graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,9 @@ void AudioGraph::PlotAudioDataToGraph(std::vector <double> *audio_data, int samp
count++;
}
}

void AudioGraph::ClearGraph()
{
max_graph_points.clear();
min_graph_points.clear();
}
25 changes: 25 additions & 0 deletions src/timeline-track-editor/src/audio-stream-container.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "audio-stream-container.h"

#include <fstream>
#include <stdio.h>


AudioStreamContainer::AudioStreamContainer()
{
input_audio_data_ptr = nullptr;
Expand Down Expand Up @@ -55,6 +59,7 @@ void AudioStreamContainer::WriteStreamContentsToFile(std::string filename, int f
sf_count_t write_count = 0;
size_t count_buffer = 0;

sf_seek(outFile, 0, SEEK_SET);
write_count = sf_write_double(outFile, stream_audio_data.front(), readSize);

sf_close(outFile);
Expand All @@ -63,3 +68,23 @@ void AudioStreamContainer::WriteStreamContentsToFile(std::string filename, int f
int AudioStreamContainer::GetFormat(){return m_format;}
int AudioStreamContainer::GetChannels(){return m_channels;}
int AudioStreamContainer::GetSampleRate(){return m_sample_rate;}

void AudioStreamContainer::ClearStreamDataStored()
{
//clear audio data stored
stream_audio_data.clear();
}

void AudioStreamContainer::ClearDataInStreamFile(std::string filename)
{
//clear audio data stored in file
if( remove( filename.c_str() ) != 0 )
{
std::cout << "\nError deleting file\n";
}
else
{
std::cout << "\nFile successfully deleted.\n";
}

}
8 changes: 8 additions & 0 deletions src/timeline-track-editor/src/audio-track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,11 @@ int AudioTrack::GetAudioTrackState(){return track_state;}

void AudioTrack::SetReferenceToPlaybackControls(PlaybackControls* controls){playbackControlsPtr = controls;}
PlaybackControls* AudioTrack::GetReferenceToPlaybackControls(){return playbackControlsPtr;}

void AudioTrack::ClearGraph()
{
m_audio_graph->ClearGraph();
Refresh();
}


18 changes: 15 additions & 3 deletions src/timeline-track-editor/src/mono-audio-track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,22 @@ void MonoAudioTrack::SetupAxisForVariable(double& start, double& end, double& re

void MonoAudioTrack::OnBrowse(wxCommandEvent& event)
{
//object to hold audio data for streaming
AudioStreamContainer audio_data_stream;

//Hold data for left channel and right channel
std::vector <double> audio_data_input_copy;

//audio format
SF_INFO input_sfinfo;

if(audio_data_stream.GetSize() == 0)
{
wxFileDialog fileDlg(this, _("Choose the WAV,FLAC,OGG file"), wxEmptyString, wxEmptyString, _("WAV file|*.wav|FLAC file|*.flac|OGG file|*.ogg|All files|*.*"));
if (fileDlg.ShowModal() == wxID_OK)
{
m_channel_track->ClearGraph();

wxString path = fileDlg.GetPath();
//use this path in your app
inputSoundFilePath = std::string(path.mb_str());
Expand All @@ -254,9 +265,6 @@ void MonoAudioTrack::OnBrowse(wxCommandEvent& event)
int channels = m_channel_track->GetNumberOfChannelsInAudioFile(inputSoundFilePath,input_sfinfo);
std::cout << "channels:" << channels << std::endl;




if(channels == 1)
{
//create a copy of file to reference for editing
Expand All @@ -268,6 +276,10 @@ void MonoAudioTrack::OnBrowse(wxCommandEvent& event)

//open file to play during streaming
audioPlayerPtr->OpenPlayerFile(streamSoundFilePath.c_str());

//clear data stored
audio_data_stream.ClearStreamDataStored();
audio_data_input_copy.clear();
}


Expand Down
Loading

0 comments on commit 5f8afe0

Please sign in to comment.