Hello and thank you for uos.
I want to implement two independent sine wave oscillators with uos that can output four discrete frequencies (891,920,941,977Hz) on a soundcard. Osc.1 is linked to the right channel and Osc.2 to the left channel of a sound device. Both oscillators must be swichted on and off independently with one of the above frequencies. I was running some tests with a modified consolesynth demo which are very promising. Nonetheless I want to ask whether my approach is the best practice. Here is the code: uos_CreatePlayer(PlayerIndex1); inindex1 := uos_AddFromSynth(PlayerIndex1,400, 0 {vol L},0.1 {vol R}, 0 {dur}, -1, -1, -1, -1 ); //init synth R inindex2 := uos_AddFromSynth(PlayerIndex1,200, 0.1 {vol L},0 {vol R}, 0 {dur}, -1, -1, -1, -1 ); //init synth L uos_AddIntoDevOut(PlayerIndex1,-1,-1,-1,-1,0,-1); uos_Play(PlayerIndex1); //start player sleep(1); uos_InputSetSynth(PlayerIndex1,inindex1, 400, -1,-1, -1,false); //mute synth R uos_InputSetSynth(PlayerIndex2,inindex2, 200, -1,-1, -1,false); //mute synth L sleep(5000); // 5sec silence uos_InputSetSynth(PlayerIndex1,inindex1, 400, -1,-1, -1,true); //unmute synth R sleep(5000); // 5sec R(400) only uos_InputSetSynth(PlayerIndex1,inindex1, 400, -1,-1, -1,false); //mute synth R uos_InputSetSynth(PlayerIndex2,inindex2, 200, -1,-1, -1,true); //unmute synth L sleep(5000); // 5sec L(200) only uos_InputSetSynth(PlayerIndex1,inindex1, 600, -1,-1, -1,true); //unmute synth R + change freq sleep(5000); // 5sec R(500)+L(200) uos_InputSetSynth(PlayerIndex1,inindex1, 400, -1,-1, -1,false); //mute synth R uos_InputSetSynth(PlayerIndex2,inindex2, 200, -1,-1, -1,false); //mute synth L sleep(5000); // 5sec silence uos_InputSetSynth(PlayerIndex2,inindex2, 300, -1,-1, -1,true); //unmute synth L + change freq sleep(5000); // 5sec L(300) only It works fine but I have two questions: - is it the best way to do it? - why do I need the sleep(1) code line after initialization of the synthesizers? If I omit sleep(1) the first tone (5sec R(400) only) remains silent. I think that the short beep (sleep(1)) after init is not causing any confusion to the tone detectors connected to the outputs of the sound card, but one can never know. Ideally the synthesizers would be initialized silently with any frequency and then triggered on demand with any of the four mentioned frequencies that is needed through uos_InputSetSynth. To give you a rough idea of the usage of the system: The RX side of the system has four HW tone detectors (891,920,941,977Hz) on it's input which trigger an UDP datagram to the opposite equipment. The uos has to reproduce the detected frequency according to the content of the received datagram towards the output on the RX side where external frequency detectors take over to trigger the appropriate actions. Thank you in advance for your help. Kindly Chris |
Administrator
|
Hello Chris.
OK, I will study your code, asap. Write you later. Fre;D |
Thank you Fred,
what I wanted to add foe better understanding is that the equipment has two receive sides: - Receive Side A through UDP port A : uos reproduces the frequency on the left channel of the audio card - Receive Side B through UDP port B : uos reproduces the frequency on the right channel of the audio card Thanks as usual for your efforts |
Administrator
|
Hello Chris.
Your code seems ok for me. > why do I need the sleep(1) code line after initialization of the synthesizers Huh, sorry I cannot reproduce. Could you give a demo-test (derived fro example from consolesynth demo) ? Thanks. Fre;D |
Hello Fred,
Forget about the sleep(1) for the moment. I read in this thread that uos (on PPi) does not need ALSA or anything else to work: https://forum.lazarus.freepascal.org/index.php/topic,31069.15.html That lead me to uninstall ALSA (as I have no need for it on the target HW and as it seems to create problems : ALSA lib pcm.c:7843:(snd_pcm_recover) underrun occurred) I did the following: - apt-get remove alsa-base - apt-get alsa-utils But still I observe error messages when I launch the sine wave generator: ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline Cannot connect to server socket err = No such file or directory Cannot connect to server request channel jack server is not running or cannot be started loading result : 0 //means loading of the library has succeeded uos unloaded and stopped //means that the sample code has terminated correctly So I am not sure whether I have completely removed the ALSA and other unnecessary components. The problem is that cracking noise is produced when the duration of the tone exceeds a certain periode of time, especially when two tones are reproduced on the left and right channel simultaneously. Do you have any advice? Kindly C |
OK, it seems that the problem is solved:
overclocking has done it. As overclocking is not provided as such on the Raspberry Pi 3 one has to disable the scaling governor (that reduces clock speed depending on processor load) like this: echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor echo performance > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor echo performance > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor echo performance > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor Now I have clean sine wave with different frequencies on left and right output of the built-in audio card. Btw, have you noticed that the frequency of the synthesizers is alway twice the set frequency? E.g. setting it to 400Hz will produce an output of 800Hz. It is not a disturbance, just to mention it. Greetings |
Administrator
|
In reply to this post by chris
Hello Chris.
> But still I observe error messages when I launch the sine wave generator Those messages come from a invalid pin-definition. Could you take a look at this: https://stackoverflow.com/questions/31603555/unknown-pcm-cards-pcm-rear-pyaudio and this https://github.com/fredvs/uos/issues/9 Do you use a another sound-cards than the one build-in of Raspberry Pi ? Fre;D |
Administrator
|
In reply to this post by chris
>E.g. setting it to 400Hz will produce an output of 800Hz. It is not a disturbance, just to mention it.
Huh, I have to check this. (did not notice it). Many thanks for the info. Fre;D |
In reply to this post by fredvs
Hello Fred,
I have only the built-in sound card of the Raspberry. For the moment I am managing quite well with the results. I get the required frequencies 891/920/941/977Hz as pure sine. Only that I have to fine-tune the settings to get the required frequency outputs on the Freq-counter connected to the output. But I suppose that this is a problem of clock inaccurracy of the PI. The error messages have no impact on the signal, but I will look into it later on. Chris |
Hello Fred,
I have encountered a problem concerning the frequency settings. By digging into the code I found in Tuos_Player.AddFromSynth() this integer calculation: StreamIn[x].Data.lensine := trunc(StreamIn[x].Data.SampleRate / Frequency) ; I suppose that this is the reason why the synthesizer output frequency can only be adjusted in steps of 9Hz? For instance if I set any frequency between 883..890Hz the output is always 893Hz Same for 891..901 which gives 902Hz and so on I suppose that this is a limitation of the Portaudio library which cannot be fixed? Chris |
Administrator
|
Hello Chris.
Well seen. I will fix it this we. Write you later. Fre;D |
Administrator
|
Hello.
Fixed float sine wave in commit 0c8cf3e..d55b116. I hope it is ok now. Fre;D |
Hello Fred,
I'm afraid that the new version has not solved the problem. The output frequency still changes in steps of 9Hz. Chris PS I was using the new liportaudio-32.dll (Not LibPortaudio-32old.dll) |
Administrator
|
Hello Chris.
OK and aaaargh. I will jump into it deeper. Write you asap. Fre;D |
Administrator
|
This post was updated on .
Re-hello Chris.
I did check and do not find something. Are you sure you used last uos commit ? I did test with consolesynth demo: ----> uos_InputSetSynth(PlayerIndex1,inindex1, 883, 1, 1, -1, true); sleep(1000); uos_InputSetSynth(PlayerIndex1,inindex1, 890,1,0.2, -1,true); sleep(1000) ; uos_InputSetSynth(PlayerIndex1,inindex1, 883, 0.2,1, -1, true); sleep(1000) ; uos_InputSetSynth(PlayerIndex1,inindex1, 890, 1,0.2, -1, true); ----> and I can clearly hear a difference between 883 and 890 Hz. But maybe I miss something.... Fre;D |
Free forum by Nabble | Edit this page |