Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.40 KB | None | 0 0
  1. use DesktopAudio version 1.0
  2.  
  3. module Test {
  4.     ports: [
  5.         mainOutputPort OutputPort {
  6.             block: Output
  7.         }
  8.         mainInputPort InputPort {
  9.             block: Input
  10.         }
  11.         propertyInputPort TestPort {
  12.             name: "test"
  13.             block: TestBlock
  14.         }
  15.     ]
  16.     blocks: [
  17.         signal Amp { domain: TestPort.domain }
  18.     ]
  19.     streams: [
  20.         TestBlock * 2 >> Amp;
  21.         Input * Amp >> Output;
  22.     ]
  23. }
  24.  
  25. AudioIn[0] >> Test(test: AudioIn[1]) >> AudioOut[0];
  26.  
  27.  
  28. -------------------------------------------------------------------------------
  29.  
  30.  
  31. // #include <iostream>
  32.  
  33. #include "ReadWriteClasses.hpp"
  34. #include "Synchronization.hpp"
  35. #include "Helper.hpp"
  36.  
  37. //[[Includes]]
  38. #include "iostream"
  39. #include "iomanip"
  40. ///////////////////////////
  41. //[[/Includes]]
  42.  
  43.  
  44. //[[Declarations]]
  45. constexpr int NUM_IN_CHANNELS = 2;
  46. constexpr int NUM_OUT_CHANNELS = 2;
  47. constexpr int NUM_SAMPLES = 44100;
  48. float inbuf[NUM_SAMPLES * NUM_IN_CHANNELS];
  49. float outbuf[NUM_SAMPLES * NUM_OUT_CHANNELS];
  50. using Amp_Helper_Type = stride::SignalHelper<double>;
  51. Amp_Helper_Type Amp_Helper{0};
  52. using Amp_Type = stride::Signal_SDRW<Amp_Helper_Type, double>;
  53. Amp_Type Amp{&Amp_Helper_Type::init_External, &Amp_Helper};
  54. //
  55. template<class TestBlock_Type,class Output_Type,class Input_Type>
  56. class Test {
  57. public:
  58.  
  59.  
  60.  
  61.     void AudioDomain_process(TestBlock_Type &TestBlock) {
  62.     }
  63.     void OutputPort_domain_process(Output_Type &Output, TestBlock_Type &Amp, Input_Type &Input) {
  64.  
  65. // Stream begin:  /home/andres/Documents/src/Stride/Stride/strideroot/frameworks/RtAudio/1.0/_tests/module/05_port_domain.stride:21
  66.         Amp.Swap();
  67.         Output = (Input * Amp.Read());
  68.     }
  69.     void TestPort_domain_process(TestBlock_Type &Amp, TestBlock_Type &TestBlock) {
  70.  
  71. // Stream begin:  /home/andres/Documents/src/Stride/Stride/strideroot/frameworks/RtAudio/1.0/_tests/module/05_port_domain.stride:20
  72.         TestBlock.Swap();
  73.         Amp.Lock();
  74.         *Amp.Write() = (TestBlock.Read() * 2);
  75.         Amp.Unlock();
  76.     }
  77. };
  78.  
  79.  
  80.  
  81. // Module call Test_0_
  82. using Test_0_Amp_Helper_Type = stride::SignalHelper<double>;
  83. Test_0_Amp_Helper_Type Test_0_Amp_Helper{0};
  84. using Test_0_Amp_Type = stride::Signal_SDRW<Test_0_Amp_Helper_Type, double>;
  85. Test_0_Amp_Type Test_0_Amp{&Test_0_Amp_Helper_Type::init_External, &Test_0_Amp_Helper};
  86. double Test_0_Input = 0;
  87. using Test_0_TestBlock_Helper_Type = stride::SignalHelper<double>;
  88. Test_0_TestBlock_Helper_Type Test_0_TestBlock_Helper{0};
  89. using Test_0_TestBlock_Type = stride::Signal_SDRW<Test_0_TestBlock_Helper_Type, double>;
  90. Test_0_TestBlock_Type Test_0_TestBlock{&Test_0_TestBlock_Helper_Type::init_External, &Test_0_TestBlock_Helper};
  91. double Test_0_Output = 0;
  92. Test<Test_0_TestBlock_Type,double,double> Test_0;
  93.  
  94.  
  95.  
  96.  
  97.  
  98. int audio_buffer_process()
  99. {
  100.     int nBufferFrames = NUM_SAMPLES;
  101.     float *in = inbuf;
  102.     float *out = outbuf;
  103.     while(nBufferFrames-- > 0) {
  104.  
  105.  
  106. // Stream begin:  /home/andres/Documents/src/Stride/Stride/strideroot/frameworks/RtAudio/1.0/_tests/module/05_port_domain.stride:25
  107.         Test_0_Input = in[0];
  108.         Test_0_TestBlock.Lock();
  109.         *Test_0_TestBlock.Write() = in[1];
  110.         Test_0_TestBlock.Unlock();
  111.         Test_0.TestPort_domain_process(Test_0_Amp, Test_0_TestBlock);
  112.         Test_0.OutputPort_domain_process(Test_0_Output, Test_0_Amp, Test_0_Input);
  113.         out[0] = Test_0_Output;
  114.  
  115.  
  116.         in += NUM_IN_CHANNELS;
  117.         out += NUM_OUT_CHANNELS;
  118.     }
  119.     return 0;
  120. }
  121. ///////////////////////////
  122. //[[/Declarations]]
  123.  
  124. //[[Instances]]
  125. //[[/Instances]]
  126.  
  127.  
  128. //[[Processing]]
  129. ///////////////////////////
  130. //[[/Processing]]
  131.  
  132. //[[OSC:Processing]]
  133. //[[/OSC:Processing]]
  134. //[[SerialIn:Processing]]
  135. //[[/SerialIn:Processing]]
  136. //[[SerialOut:Processing]]
  137. //[[/SerialOut:Processing]]
  138.  
  139.  
  140. int main() {
  141. // std::cout << "app started" << std::endl;
  142. //[[Initialization]]
  143.  
  144.  
  145.     for(int i = 0; i < NUM_SAMPLES; i++) {
  146.         inbuf[i* NUM_IN_CHANNELS] = (i * 2.0 / (NUM_SAMPLES-1)) - 1; // -1 -> 1
  147.         inbuf[i* NUM_IN_CHANNELS + 1] = 1 - (i * 2.0 / (NUM_SAMPLES-1)); // 1 -> -1
  148.     }
  149.  
  150.     audio_buffer_process();
  151.     ///////////////////////////
  152. //[[/Initialization]]
  153.  
  154.     // char input;
  155.     // std::cout << "\nRunning ... press <enter> to quit.\n";
  156.     // std::cin.get(input);
  157.  
  158. //[[Cleanup]]
  159.  
  160.     for(int i = 0; i < NUM_SAMPLES * NUM_IN_CHANNELS; i++) {
  161.         std::cout << std::setprecision(10) << outbuf[i] << std::endl;
  162.     }
  163.     ///////////////////////////
  164. //[[/Cleanup]]
  165.  
  166.     return 0;
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement