diff --git a/.gitignore b/.gitignore index ab7eb80937d8ff8e91d8f5bf1471efb3e5395879..edeeaf1189c3cbb881bd3ea516cd45429205e511 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,8 @@ examples/socket_server_2.exe examples/socket_server_2.o examples/socket_server.exe examples/socket_server.o +examples/sound_input.exe +examples/sound_input.o examples/matlab/LPF_8000_11025.coef examples/matlab/LPF_8000_48000.coef examples/asynchronous_CT.dot @@ -66,3 +68,6 @@ examples/DSP_socket_client examples/DSP_socket_client_2 examples/DSP_socket_server examples/DSP_socket_server_2 +examples/DSP_sound_input +examples/captured_sample.wav +examples/sound_input.dot diff --git a/CHANGELOG b/CHANGELOG index 1f233a41fc90a6abe52053772c862a4f2a14694d..766bdcc19125bc3baff146103ddc4a7e271773fb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,6 +12,7 @@ CHANGES: - Added to DSP_types.h a SOUND_object_t abstract class, a wrapper for different sound cards' API - Added WMM_object_t abstract class, a wrapper for Windows MultiMedia API - DSP::u::AudioOutput now uses SOUND_object_t (currently just WMM_object_t) for soundcard API + - Added examples/sound_input.cpp with DSP::u::AudioInput example - ver. 0.20.004 - <b>2021.04.06</b> Changed: - Fixed makefiles for Linux - install and examples compilation works diff --git a/examples/makefile b/examples/makefile index 720617fb040668d47fcbfc8b2097e530b2dd8d94..e746da42abb6b5e7e91c88d700f4420f4e10ef24 100644 --- a/examples/makefile +++ b/examples/makefile @@ -27,7 +27,7 @@ endif SRCS = hello.cpp -all: hello.exe echo.exe multirate.exe callbacks.exe socket_server.exe socket_client.exe socket_server_2.exe socket_client_2.exe macro_example.exe asynchronous.exe asynchronous_CT.exe +all: hello.exe echo.exe sound_input.exe multirate.exe callbacks.exe socket_server.exe socket_client.exe socket_server_2.exe socket_client_2.exe macro_example.exe asynchronous.exe asynchronous_CT.exe #all: echo.exe hello.o: $(SRC_DIR)/hello.cpp @@ -40,6 +40,11 @@ echo.o: $(SRC_DIR)/echo.cpp echo.exe: echo.o $(CC) -L"$(DSPELIB_DIR_ROOT)/$(TYPE)" "$(SRC_DIR)/echo.o" -o"$(SRC_DIR)/echo.exe" $(LINKER_FLAGS) -lDSPE -lwinmm +sound_input.o: $(SRC_DIR)/sound_input.cpp + $(CC) -DWIN32 -I"$(DSPELIB_DIR_ROOT)/include" -I"$(DSPELIB_DIR_ROOT)/include/$(TYPE)" $(CFLAGS) -c $(SRC_DIR)/sound_input.cpp -o "$(SRC_DIR)/sound_input.o" +sound_input.exe: sound_input.o + $(CC) -L"$(DSPELIB_DIR_ROOT)/$(TYPE)" "$(SRC_DIR)/sound_input.o" -o"$(SRC_DIR)/sound_input.exe" $(LINKER_FLAGS) -lDSPE -lwinmm + multirate.o: $(SRC_DIR)/multirate.cpp $(CC) -DWIN32 -I"$(DSPELIB_DIR_ROOT)/include" -I"$(DSPELIB_DIR_ROOT)/include/$(TYPE)" $(CFLAGS) -c "$(SRC_DIR)/multirate.cpp" -o "$(SRC_DIR)/multirate.o" multirate.exe: multirate.o @@ -89,6 +94,7 @@ asynchronous_CT.exe: asynchronous_CT.o clean: rm -f $(SRC_DIR)/hello.exe $(SRC_DIR)/hello.o rm -f $(SRC_DIR)/echo.exe $(SRC_DIR)/echo.o + rm -f $(SRC_DIR)/sound_input.exe $(SRC_DIR)/sound_input.o rm -f $(SRC_DIR)/asynchronous.exe $(SRC_DIR)/asynchronous.o rm -f $(SRC_DIR)/asynchronous_CT.exe $(SRC_DIR)/asynchronous_CT.o rm -f $(SRC_DIR)/multirate.exe $(SRC_DIR)/multirate.o @@ -104,5 +110,6 @@ clean: rm -f $(SRC_DIR)/morse.wav rm -f $(SRC_DIR)/morse_key.wav rm -f $(SRC_DIR)/test_out.wav + rm -f $(SRC_DIR)/captured_sample.wav rm -f $(SRC_DIR)/*.dot rm -f $(SRC_DIR)/*.gif diff --git a/examples/makefile-m64.linux b/examples/makefile-m64.linux index 26854ec42a6282408138d16a9bfebe6e4163289e..f2fecda3b2663a302aed8f5d0d39d6f724655304 100644 --- a/examples/makefile-m64.linux +++ b/examples/makefile-m64.linux @@ -32,7 +32,7 @@ LIBS_SOCKETS = -lDSPEsockets # -lws2_32 SRCS = hello.cpp #all: hello.exe echo.exe multirate.exe callbacks.exe socket_server.exe socket_client.exe #socket_server_2.exe socket_client_2.exe macro_example.exe asynchronous.exe asynchronous_CT.exe -all: DSP_hello DSP_echo DSP_multirate DSP_callbacks DSP_socket_server DSP_socket_client DSP_socket_server_2 DSP_socket_client_2 DSP_macro_example DSP_asynchronous DSP_asynchronous_CT +all: DSP_hello DSP_echo DSP_sount_input DSP_multirate DSP_callbacks DSP_socket_server DSP_socket_client DSP_socket_server_2 DSP_socket_client_2 DSP_macro_example DSP_asynchronous DSP_asynchronous_CT hello.o: $(SRC_DIR)/hello.cpp $(CC) $(DFLAGS) -I"$(DSPELIB_DIR_ROOT)/include" -I"$(DSPELIB_DIR_ROOT)/include/$(TYPE)" $(CFLAGS) -c "$(SRC_DIR)/hello.cpp" -o "$(SRC_DIR)/hello.o" @@ -46,6 +46,12 @@ echo.o: $(SRC_DIR)/echo.cpp DSP_echo: echo.o $(CC) -L"$(DSPELIB_DIR_ROOT)/$(TYPE)" "$(SRC_DIR)/echo.o" -o "$(SRC_DIR)/DSP_echo" $(LINKER_FLAGS) $(LIBS) +sount_input.o: $(SRC_DIR)/sount_input.cpp + $(CC) $(DFLAGS) -I"$(DSPELIB_DIR_ROOT)/include" -I"$(DSPELIB_DIR_ROOT)/include/$(TYPE)" $(CFLAGS) -c "$(SRC_DIR)/sount_input.cpp" -o "$(SRC_DIR)/sount_input.o" + +DSP_sount_input: sount_input.o + $(CC) -L"$(DSPELIB_DIR_ROOT)/$(TYPE)" "$(SRC_DIR)/sount_input.o" -o "$(SRC_DIR)/DSP_sount_input" $(LINKER_FLAGS) $(LIBS) + multirate.o: $(SRC_DIR)/multirate.cpp $(CC) $(DFLAGS) -I"$(DSPELIB_DIR_ROOT)/include" -I"$(DSPELIB_DIR_ROOT)/include/$(TYPE)" $(CFLAGS) -c "$(SRC_DIR)/multirate.cpp" -o "$(SRC_DIR)/multirate.o" @@ -104,6 +110,7 @@ DSP_asynchronous_CT: asynchronous_CT.o clean: rm -f $(SRC_DIR)/DSP_hello $(SRC_DIR)/hello.o rm -f $(SRC_DIR)/DSP_echo $(SRC_DIR)/echo.o + rm -f $(SRC_DIR)/DSP_sound_input $(SRC_DIR)/sound_input.o rm -f $(SRC_DIR)/DSP_asynchronous $(SRC_DIR)/asynchronous.o rm -f $(SRC_DIR)/DSP_asynchronous_CT $(SRC_DIR)/asynchronous_CT.o rm -f $(SRC_DIR)/DSP_multirate $(SRC_DIR)/multirate.o @@ -119,5 +126,6 @@ clean: rm -f $(SRC_DIR)/morse.wav rm -f $(SRC_DIR)/morse_key.wav rm -f $(SRC_DIR)/test_out.wav + rm -f $(SRC_DIR)/captured_sample.wav rm -f $(SRC_DIR)/*.dot rm -f $(SRC_DIR)/*.gif diff --git a/examples/rundot.bat b/examples/rundot.bat index 0e6889dc1c8ea49c20c0843412881f9fdef1ef4f..f748853667c9a900b7d6ec278cd0dfe376fc6382 100644 --- a/examples/rundot.bat +++ b/examples/rundot.bat @@ -9,4 +9,5 @@ dot -Tgif socket_client_2.dot -osocket_client_2.gif dot -Tgif callbacks_scheme.dot -ocallbacks_scheme.gif dot -Tgif hello.dot -ohello.gif dot -Tgif echo.dot -oecho.gif +dot -Tgif captured_sample.dot -ocaptured_sample.gif dot -Tgif multirate.dot -omultirate.gif diff --git a/examples/sound_input.cpp b/examples/sound_input.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f1f1bc5c187a872a2f70d40390d59ef0404fd4ff --- /dev/null +++ b/examples/sound_input.cpp @@ -0,0 +1,60 @@ +/*! Digital Signal Processing Engine Sound capture usage example. + * \author Marek Blok + * \date 2021.05.13 + * \date updated 2021.01.18 + */ +#include <DSP_lib.h> + +#ifndef _DSPE_TEST_ +int main(void) +#else +#include "DSPE_examples.h" +int test_sound_input(void) +#endif // _DSPE_TEST_ +{ + DSP::Clock_ptr MasterClock, AudioInClock; + string tekst; + int temp; + long int Fp, Fp2; + + DSP::log.SetLogState(DSP::e::LogState::console | DSP::e::LogState::file); + DSP::log.SetLogFileName("log_file.log"); + + DSP::log << DSP::lib_version_string() << endl << endl; + DSP::log << "Sound input example" << endl; + + MasterClock=DSP::Clock::CreateMasterClock(); + + DSP::u::WaveInput WaveIn(MasterClock, "DSPElib.wav", "."); + Fp = WaveIn.GetSamplingRate(); + + DSP::u::AudioOutput AudioOut(Fp); + + WaveIn.Output("out") >> AudioOut.Input("in"); + + Fp2 = 8000; + long Fp_gcd = DSP::f::gcd(Fp, Fp2); + AudioInClock=DSP::Clock::GetClock(MasterClock, Fp2 / Fp_gcd, Fp / Fp_gcd); + DSP::u::AudioInput AudioIn(AudioInClock, 8000, 1); + DSP::u::FileOutput WaveOut("captured_sample.wav",DSP::e::SampleType::ST_short, 1, DSP::e::FileType::FT_wav, Fp2); + + AudioIn.Output("out") >> WaveOut.Input("in"); + + DSP::Component::CheckInputsOfAllComponents(); + DSP::Clock::SchemeToDOTfile(MasterClock, "sound_input.dot"); + + temp=1; + do + { + DSP::Clock::Execute(MasterClock, Fp/8); + + DSP::log << "MAIN" << DSP::e::LogMode::second << temp << endl; + temp++; + } + while (WaveIn.GetBytesRead() != 0); + + DSP::Clock::FreeClocks(); + DSP::log << DSP::e::LogMode::Error << "MAIN" << DSP::e::LogMode::second << "end" << endl; + + return 0; +}