diff --git a/include/Frame.h b/include/Frame.h index 5f80528e..7eb107f6 100644 --- a/include/Frame.h +++ b/include/Frame.h @@ -77,6 +77,15 @@ namespace openshot /// Display the wave form void DisplayWaveform(bool resize); + /// Get an array of sample data + float* GetAudioSamples(int channel); + + /// Get number of audio channels + int GetAudioChannelsCount(); + + /// Get number of audio channels + int GetAudioSamplesCount(); + /// Get pixel data (as packets) const Magick::PixelPacket* GetPixels(); diff --git a/src/Frame.cpp b/src/Frame.cpp index 5e2a096d..83c15d09 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -243,6 +243,25 @@ void Frame::DisplayWaveform(bool resize) wave_image.display(); } +// Get an array of sample data +float* Frame::GetAudioSamples(int channel) +{ + // return JUCE audio data for this channel + return audio->getSampleData(channel); +} + +// Get number of audio channels +int Frame::GetAudioChannelsCount() +{ + return audio->getNumChannels(); +} + +// Get number of audio samples +int Frame::GetAudioSamplesCount() +{ + return audio->getNumSamples(); +} + // Get pixel data (as packets) const Magick::PixelPacket* Frame::GetPixels() { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fd765635..69b3a50d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -40,6 +40,7 @@ add_executable(tester Cache_Tests.cpp Coordinate_Tests.cpp FileReaderBase_Tests.cpp + FFmpegReader_Tests.cpp Fraction_Tests.cpp FrameMapper_Tests.cpp FrameRate_Tests.cpp diff --git a/tests/FFmpegReader_Tests.cpp b/tests/FFmpegReader_Tests.cpp new file mode 100644 index 00000000..9dea5c23 --- /dev/null +++ b/tests/FFmpegReader_Tests.cpp @@ -0,0 +1,36 @@ +#include "UnitTest++.h" +#include "../include/OpenShot.h" + +using namespace std; +using namespace openshot; + +TEST(FFmpegReader_Invalid_Path) +{ + // Check invalid path + CHECK_THROW(FFmpegReader r(""), InvalidFile); +} + +TEST(FFmpegReader_Check_Audio_File) +{ + // Create a reader + FFmpegReader r("../../src/examples/piano.wav"); + + // Get frame 1 + Frame f = r.GetFrame(1); + + // Get the number of channels and samples + float *samples = f.GetAudioSamples(0); + + // Check audio properties + CHECK_EQUAL(2, f.GetAudioChannelsCount()); + CHECK_EQUAL(267, f.GetAudioSamplesCount()); + + // Check actual sample values (to be sure the waveform is correct) + CHECK_CLOSE(0.0f, samples[0], 0.00001); + CHECK_CLOSE(0.0f, samples[50], 0.00001); + CHECK_CLOSE(0.0f, samples[100], 0.00001); + CHECK_CLOSE(0.0f, samples[200], 0.00001); + CHECK_CLOSE(0.164062f, samples[230], 0.00001); + CHECK_CLOSE(-0.164062f, samples[266], 0.00001); +} +