Re: [LAD] Cli sound file player requirements
On Mon, 10 May 2021 00:31:18 +0100 Filipe Coelho wrote: > > On Sun, 9 May 2021 19:07:37 +0100 Filipe Coelho wrote: > >> > >> $ /usr/lib/carla/carla-bridge-native internal "~/Music/nyan.wav" audiofile > > I ran this before writing to the mailing list, so for sure it works here. Thanks Filipe, I didn't doubt it. > Might be you have v2.2 or even older version of Carla, passing the > filename like that requires v2.3 Yes, I didn't have carla installed, but I installed the (Mint 20) package. It was indeed "even older" at 2.1. 2.3 installed now and all is well. -- Thanks again, John. ___ Linux-audio-dev mailing list Linux-audio-dev@lists.linuxaudio.org https://lists.linuxaudio.org/listinfo/linux-audio-dev
[LAD] Converting single-cycle wave to harmonic spectrum
Hey hey, I'm trying to convert a single cycle wave to a harmonic spectrum. I know that in theory this is a job for standard FFT. I wondered if there isn't a "simpler" way given a few assumptions about the input. The input waveform is exactly one single cycle The waveform has only harmonic overtones. That means that only integral multiples of the base frequency need to be considered and the specific Nyquist frequency is determined by the number of samples (I think). I treid searching, but it appears that I don't have the right keyword to hand, getting only very general results bordering on the off-topic. :) Can anyone help? A good keyword, name of an algorithm or a general name for this specific task would be helpful enough, I suppose. Best wishes, Jeanette -- * Website: http://juliencoder.de - for summer is a state of sound * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g * Audiobombs: https://www.audiobombs.com/users/jeanette_c * GitHub: https://github.com/jeanette-c She's so lucky, she's a star But she cry, cry, cries in her lonely heart... <3 (Britney Spears) ___ Linux-audio-dev mailing list Linux-audio-dev@lists.linuxaudio.org https://lists.linuxaudio.org/listinfo/linux-audio-dev
Re: [LAD] Converting single-cycle wave to harmonic spectrum
On Mon, May 10, 2021 at 12:20:56PM +0200, Jeanette C. wrote: > The input waveform is exactly one single cycle > The waveform has only harmonic overtones. You may be making a dangerous assumption (if you want an accurate result): that a single cycle corresponds exactly to an integer number of samples. If that is the case, all you need is an FFT size equal to the number of samples, AFAIK, fftw3 can do any size. Then each bin of the FFT output will correspond exactly to an harmonic. But in general, a single cycle will not be an integer number of samples, and in that case there is no simple solution. Suppose you have N samples, but the actaul period is N + eps, with 0 < eps < 1. If you know eps, you could resample the signal to an integer number of samples or to some preferred FFT size. But now we have a new problem: in order to do the resampling you'll need some extra samples either before or after the ones you started with. If these are available, and if you know that they are valid (i.e. they represent an identical cycle), that is probably the way to go. And if not, there is no 'exact' solution. Maybe you could tell us what exactly you want to use this for, then a pragmatic solution could be found. Ciao, -- FA ___ Linux-audio-dev mailing list Linux-audio-dev@lists.linuxaudio.org https://lists.linuxaudio.org/listinfo/linux-audio-dev
Re: [LAD] Converting single-cycle wave to harmonic spectrum
May 10 2021, Fons Adriaensen has written: ... Maybe you could tell us what exactly you want to use this for, then a pragmatic solution could be found. There are numerous audiofiles around containing one single cycle wave to be used with multiple wavetable synthesizers, both in hard and software. I can only assume that these are matched to the number of samples they contain. Some of them CERTAINLY proclaimed this fact, AFAIK. I don't have a wavetable synth that would directly accept waves, but I have access to synthesizers with additive capabilities, including Yoshimi. So converting such "prepared" waveforms to additive spectra is quite useful. I already have a more general solution in Csound, which works with a generic FFT, to be used with real world samples. But it takes some time and contains its own hazards. :) So a dedicated solution seemed preferrable. Many thanks for your clear description and the useful caveats so far! Best wishes, Jeanette -- * Website: http://juliencoder.de - for summer is a state of sound * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g * Audiobombs: https://www.audiobombs.com/users/jeanette_c * GitHub: https://github.com/jeanette-c She's so lucky, she's a star But she cry, cry, cries in her lonely heart... <3 (Britney Spears) ___ Linux-audio-dev mailing list Linux-audio-dev@lists.linuxaudio.org https://lists.linuxaudio.org/listinfo/linux-audio-dev
Re: [LAD] Converting single-cycle wave to harmonic spectrum
On Mon, May 10, 2021 at 03:17:12PM +0200, Jeanette C. wrote: > There are numerous audiofiles around containing one single cycle wave to > be used with multiple wavetable synthesizers, both in hard and software. > I can only assume that these are matched to the number of samples they > contain. Some of them CERTAINLY proclaimed this fact, OK. In that case the actual frequency will be R / N where R is the sample rate and N the length in samples. This is very probably not exactly an musical pitch in the equally tempered scale, but that doesn't matter since the wavetable synth will have to resample it anyway. So in this case, all you need is an FFT with a size equal to the lenght of your single cycle sample. There is no faster method. I just checked, FFTW3 can do any size. Normally you'd just use the real-to-complex fft. For prime lengths, this may become slower than normal (N^2 complexity instead of N log N). If this matters (it probably won't), you could use the complex-to-complex fft with the imaginary part set to zero, this will be faster (always N log N). In all cases, the N / 2 + 1 first elements of the output will correspond to the harmonics, so you just the square root of the power of each. Ciao, -- FA ___ Linux-audio-dev mailing list Linux-audio-dev@lists.linuxaudio.org https://lists.linuxaudio.org/listinfo/linux-audio-dev
Re: [LAD] Converting single-cycle wave to harmonic spectrum
On Mon, 10 May 2021 15:51:38 +0200 Fons Adriaensen wrote: >On Mon, May 10, 2021 at 03:17:12PM +0200, Jeanette C. wrote: > >> There are numerous audiofiles around containing one single cycle wave to >> be used with multiple wavetable synthesizers, both in hard and software. >> I can only assume that these are matched to the number of samples they >> contain. Some of them CERTAINLY proclaimed this fact, > >OK. In that case the actual frequency will be R / N where R is the sample >rate and N the length in samples. This is very probably not exactly an >musical pitch in the equally tempered scale, but that doesn't matter >since the wavetable synth will have to resample it anyway. > >So in this case, all you need is an FFT with a size equal to the lenght >of your single cycle sample. There is no faster method. > >I just checked, FFTW3 can do any size. > >Normally you'd just use the real-to-complex fft. For prime lengths, this >may become slower than normal (N^2 complexity instead of N log N). If this >matters (it probably won't), you could use the complex-to-complex fft with >the imaginary part set to zero, this will be faster (always N log N). > >In all cases, the N / 2 + 1 first elements of the output will correspond >to the harmonics, so you just the square root of the power of each. > >Ciao, > Not entirely clear on what you are doing, but you may find PadSynth the be a better option. It already creates perfectly looping samples (not sure if you can fiddle that for a single cycle) and will then export these over as a number of different pitches/key numbers. -- Will J Godfrey https://willgodfrey.bandcamp.com/ http://yoshimi.github.io Say you have a poem and I have a tune. Exchange them and we can both have a poem, a tune, and a song. ___ Linux-audio-dev mailing list Linux-audio-dev@lists.linuxaudio.org https://lists.linuxaudio.org/listinfo/linux-audio-dev
Re: [LAD] Cli sound file player requirements
I'm convinced Jack transport, using 'carla-bridge-native' and controlled by jack_transport CLI tool, is the easiest way to go. I'll use Qprocesses initially and work on using the API later. QJackCtl sources led me to jack_transport_query and QtCreator makes it easy to follow the code, so I hope to use that for transport time display. I did get ecasound to play Ok just once. Then tried the same line with a '-c' and got over a thousand Xruns before I could hit ^c. Tried the line which worked, again, and got similar results to the try with '-c'. Python just doesn't work for me. It used to, but it seems a bit of a mess these days, for users at my level, while the two versions are in situ. Thanks for the suggestion though. Qt Creator is probably the most helpful software I've ever used, in any field, and I've been using for a long time... -- Thanks again, John. ___ Linux-audio-dev mailing list Linux-audio-dev@lists.linuxaudio.org https://lists.linuxaudio.org/listinfo/linux-audio-dev
Re: [LAD] Cli sound file player requirements
On 10/05/21 16:42, John Murphy wrote: I'm convinced Jack transport, using 'carla-bridge-native' and controlled by jack_transport CLI tool, is the easiest way to go. I'll use Qprocesses initially and work on using the API later. QJackCtl sources led me to jack_transport_query and QtCreator makes it easy to follow the code, so I hope to use that for transport time display. I did get ecasound to play Ok just once. Then tried the same line with a '-c' and got over a thousand Xruns before I could hit ^c. Tried the line which worked, again, and got similar results to the try with '-c'. Python just doesn't work for me. It used to, but it seems a bit of a mess these days, for users at my level, while the two versions are in situ. Thanks for the suggestion though. Qt Creator is probably the most helpful software I've ever used, in any field, and I've been using for a long time... If you are going to write some code for it, maybe best to control the whole thing with the JACK API. Or maybe even better, calling into carla API. I did a quick test for this just now, this snippet is all you need. ``` #include "CarlaHost.h" #include #ifdef __cplusplus using namespace CarlaBackend; #endif int main() { CarlaHostHandle host = carla_standalone_host_init(); carla_engine_init(host, "JACK", "AudioPlayback"); carla_add_plugin(host, BINARY_NATIVE, PLUGIN_INTERNAL, NULL, "nyan", "audiofile", 0, NULL, PLUGIN_OPTIONS_NULL); carla_set_custom_data(host, 0, CUSTOM_DATA_TYPE_STRING, "file", "./nyan.wav"); for (;;) { carla_engine_idle(host); sleep(1); } carla_engine_close(host); } ``` Build with: $ gcc playaudio.c $(pkg-config --cflags --libs carla-standalone) -o playaudio API Documentation at https://kx.studio/ns/dev-docs/CarlaBackend/group__CarlaHostAPI.html ___ Linux-audio-dev mailing list Linux-audio-dev@lists.linuxaudio.org https://lists.linuxaudio.org/listinfo/linux-audio-dev
Re: [LAD] Cli sound file player requirements
On Mon, 10 May 2021 17:04:41 +0100 Filipe Coelho wrote: > On 10/05/21 16:42, John Murphy wrote: > > I'm convinced Jack transport, using 'carla-bridge-native' and > > controlled by jack_transport CLI tool, is the easiest way to go. > > I'll use Qprocesses initially and work on using the API later. > > If you are going to write some code for it, maybe best to control the > whole thing with the JACK API. > > Or maybe even better, calling into carla API. > I did a quick test for this just now, this snippet is all you need. [snippet snipped] > API Documentation at > https://kx.studio/ns/dev-docs/CarlaBackend/group__CarlaHostAPI.html So few lines when you know how. Thank you so much for that. There was one warning about a "Carla assertion failure": "strBuf != nullptr" in file ../../utils/CarlaUtils.hpp, line 370 A couple of arguments to it would make it perfect, if you have time. Just file name and transport position would do. -- Thanks again, John. ___ Linux-audio-dev mailing list Linux-audio-dev@lists.linuxaudio.org https://lists.linuxaudio.org/listinfo/linux-audio-dev
Re: [LAD] Converting single-cycle wave to harmonic spectrum
Hi Fons, many thanks again, I already have the documentation for fftw open in my browser. It doesn't look complicated at all for such a simple case. Best wishes, Jeanette -- * Website: http://juliencoder.de - for summer is a state of sound * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g * Audiobombs: https://www.audiobombs.com/users/jeanette_c * GitHub: https://github.com/jeanette-c But tell me what happens when it stops? <3 (Britney Spears) ___ Linux-audio-dev mailing list Linux-audio-dev@lists.linuxaudio.org https://lists.linuxaudio.org/listinfo/linux-audio-dev
Re: [LAD] Converting single-cycle wave to harmonic spectrum
Hi Fons and you other FFT initiates, I have written a simple test program (end of this mail) that produces two sine waves one octave apart. I used the FFTW_R2HC plan, which operates on two double arrays. The output can be read as two halves: up to half the array: output[k] = real[k] the real part of the FFT The second half: output[size -k] = imaginary[k], the imaginary/complex part of the FFT The output shows 0 for the first to real values, but the same strength for the first two imaginary parts. Is this to be expected? Best wishes (code below), Jeanette *** fft_test.cpp *** // g++ -o fft_test fft_test.cpp -lfftw3 -lm #include #include #include using namespace std; int main() { // Create input, output arrays and allocate them double *in, *out; in = (double *) fftw_malloc(sizeof(double) * 2048); out = (double *) fftw_malloc(sizeof(double) * 2048); // Create the fftw plan: halfcomplex out[k] = real[k] out[size-k] = im[k] fftw_plan conv_plan = fftw_plan_r2r_1d(2048, in, out, FFTW_R2HC, FFTW_ESTIMATE); // Create input, two sinewaves one octave apart for (int i = 0;i<2048;i++) { in[i] = sin(M_PI * i/1024) + sin(M_PI * i/512); } // Now execute the FFT on the in-array fftw_execute(conv_plan); // "beautify" the output, by setting everything below 10^(-10) to zero for (int i = 0;i<2048;i++) { if (abs(out[i]) < 1e-10) { out[i] = 0; } } // Print the first 16 harmonics, both real and imaginary parts (see // half-complex fftw plan FFTW_R2HC) for (int i = 0;i<16;i++) { cout << "Harm[" << i << "] = " << out[i] << ", " << out[2047 - i] << endl; } // Free everything fftw_destroy_plan(conv_plan); fftw_free(in); fftw_free(out); return 0; } *** end of file *** -- * Website: http://juliencoder.de - for summer is a state of sound * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g * Audiobombs: https://www.audiobombs.com/users/jeanette_c * GitHub: https://github.com/jeanette-c But tell me what happens when it stops? <3 (Britney Spears) ___ Linux-audio-dev mailing list Linux-audio-dev@lists.linuxaudio.org https://lists.linuxaudio.org/listinfo/linux-audio-dev
Re: [LAD] Converting single-cycle wave to harmonic spectrum
On Mon, May 10, 2021 at 11:00:10PM +0200, Jeanette C. wrote: > The output can be read as two halves: > up to half the array: > output[k] = real[k] the real part of the FFT > The second half: > output[size -k] = imaginary[k], the imaginary/complex part of the FFT > The output shows 0 for the first to real values, but the same strength for > the first two imaginary parts. Is this to be expected? Yes. The sin() waves appear in the imaginary part, if you would have used cos() instead that would show up in the real part. In general you will have both, and * the amplitude is hypot (real, imag). * the phase is atan2 (imag, real). Ciao, -- FA ___ Linux-audio-dev mailing list Linux-audio-dev@lists.linuxaudio.org https://lists.linuxaudio.org/listinfo/linux-audio-dev
Re: [LAD] Converting single-cycle wave to harmonic spectrum
Hi Fons, thanks again. Now it's all clear. I should have remember about the sine and cosine thing. :( May 10 2021, Fons Adriaensen has written: * the amplitude is hypot (real, imag). * the phase is atan2 (imag, real). This is really helpful! Best wishes, Jeanette Ciao, -- FA -- * Website: http://juliencoder.de - for summer is a state of sound * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g * Audiobombs: https://www.audiobombs.com/users/jeanette_c * GitHub: https://github.com/jeanette-c But tell me what happens when it stops? <3 (Britney Spears) ___ Linux-audio-dev mailing list Linux-audio-dev@lists.linuxaudio.org https://lists.linuxaudio.org/listinfo/linux-audio-dev
Re: [LAD] Cli sound file player requirements
On Mon, 10 May 2021 18:36:02 +0100 John Murphy wrote: > > A couple of arguments to it would make it perfect, if you have time. > > Just file name and transport position would do. It's OK. I was being lazy and it was surprisingly easy :) -- Thanks again, John. ___ Linux-audio-dev mailing list Linux-audio-dev@lists.linuxaudio.org https://lists.linuxaudio.org/listinfo/linux-audio-dev