AudioResearchBlog

Covering all audio related stuff with special focus on programming and digital signal processing

Archive for the 'algorithms' Category

Some experience with CLAM inside an audio club at FIUBA, Argentina

Posted by hordia on 11th March 2010

(Note: I wrote this as something to tell to the clam-devel mailing list about some of my source-code commits)

About eight months ago, there was a foundation of something like an “audio club” in my university [1]. As soon i learned about that, i quickly got in touch with them and noticed that there was a major interest in analog issues (the only audio area with at least elective, courses in the university). So i told them about all the cool things that are available and ready to do with digital audio, mostly signal processing related. I talked in general, but of course i also talked about clam, with all its prototyping, real-time and easy development of plugins features. Even many of them ended installing and using it, and some even developing with more or less help. One thing to notice is that most of them are students from first years and most (but not all) are students with a basic programming level (because they are from electronics) but strong dsp knowledge (behind this is an university with more emphasis in theory than practice)
We started specifying plugins from a more abstract level (inputs/outputs/controls) and generating the source code base using
CLAM’s Templated Plugins Code Generator [2] and prototyping some simple applications. But one of the things we ended up doing was to take advantage of clam as platform to prototype medic related applications like filter ECG signal from noise in realtime, and some like _vice-versa_, i mean applying some processing knowledge from that area to audio.

Some of that work (one hour per week average) it’s now in the repo, most remarkable i think are filters work, by above the adaptative notch one (which even was used as a demo of a talk of one of the members about the steepest descent algorithm and its application to filter ECG signals)

Some development screenshots:
http://clam-project.org/wiki/Image:FilterByCoefExample.jpg
http://clam-project.org/wiki/Image:FilterExample-LP-HP.jpg
http://clam-project.org/wiki/Image:ThreeBandFilterOutputWithWhiteNoiseAsInput.jpg
http://clam-project.org/wiki/Image:GaussianWhiteNoiseHistogram.jpg
http://clam-project.org/wiki/Image:UniformWhiteNoiseHistogram.jpg

[0] FIUBA: Engineering Faculty of Buenos Aires University
[1] Group: http://code.google.com/p/club-audio-fiuba
Source code repo: http://groups.google.com/group/club_de_audio_fiuba
[2] http://audiores.uint8.com.ar/blog/2009/08/17/showing-a-little-about-clam-as-a-prototyping-tool-at-the-audio-club-of-fiuba/


, , , , , , , , , , , , , , , , , , ,

Posted in audio, algorithms, effects, signal processing, free software, programming, matlab, GPL, c++, blog, noise, python, projects, math, English, CLAM, news, plugins, ideas, ClubAudioFiuba | No Comments »

La historia de Horgand (conversación con holborn)

Posted by hordia on 28th June 2008

Hace bastante tiempo que tenia archivada esta conversación sobre síntesis por FM y Horgand que quería publicar.

Qué es Horgand? un sintetizador por soft capaz de realizar sonidos de órgano y otros tipos de sonido como pianos eléctricos (Rhodes , Wurlitzer, DX E.Piano ), Jazz Guitar, Strings, Brass, Fretless Bass, Accordion etc. Esta basado en síntesis por FM, según su web:

“Is based on a FM audio synthesizer with twenty carriers (20) without modulators in a plain based algorithm.
each carrier frequency can be modified for construct complex sounds. The synthesizer incorporate also a LFO (Low frequency oscillator) for generate tremolo effects and detune effects applying LFO Pitch and Amplitude to the carrier frequency’s. Some synthesizer parameters can be edited for each sound including two ADSR, (Normal and Percussion), Fine Frequency, Attenuation, Rotary Amplitude, Transpose, etc. Four DSP effects are available for obtain more complex sounds, Rotary, Chorus, Delay and Reverberation. Sounds are stored in banks of 32 organ sounds and can be changed externally with MIDI program change (1-32).”

También incorpora reconocimiento de acordes para producir acompañamiento automático (bajo y bateria) y con líneas de bajo editables para cada ritmo.

Ejemplo de como suena: Horgand_demo.ogg

No conozco mucho de síntesis por FM y tenía curiosidad de como lograba el sonido y terminó saliendo una especie de entrevista improvisada, creo que puede ser interesante para quienes quieran adentrarse en este tipo de programación.

La conversación:

<hordia> despues me tenes que contar en que te basaste para conseguir el sonido de horgand digitalmente…
<holborn> pues en el DX7 …. tiene 32 algoritmos de colocacion de los operadores … pero si usas el plano (todos en linea)… todo lo que hagas suena a organo … a partir de ahi … pues añadirle los efectos … y claro en vez de 6 “osciladores” hay 10 … que en realidad son 20 … con lo cual pues es mas rico que un emulador de dx7 tipo hexter o en el dx7 mismo … en realidad .. para usar 20 osciladores no chupa CPU nada … otros porgramas usan 3 y ch
<holborn> claro que para ahorrar cpu .. tuve que limitar algunos parametros de edicion … pero bueno … yo lo que queria era que sonara … si nadie se pone a editar sonidos … ni dios vaya …
<hordia> que es el DX7? :P me suena a un teclado legendario pero no estoy seguro…

<holborn> el DX7 fue el primer sintetizador FM … es de yamaha .. y fue una revolucion porque era el primero que mas o menos imitaba bien sonidos reales … algunos mejor que otros …
<holborn> los vendieron todos y mas …
<holborn> yo realmente era un experto … en aquella epoca ni dios sabia nada de musica electronica … yo me hice un curso que daba un loco de la musica electronica .. y sabia programar sintes cosa que nadie sabia .. te estoy hablando de hace mil años …
<holborn> cuando salio el DX7 pues me tuve que empapar toda la info porque realmente es muy diferente a un sinte analogico tradicional … y bueno .. le pedi a un amigo que trabajaba en un distribuidor de yamaha .. que me consiguiera info de verdad … de hecho todavia la conservo ..por ahi ..
<hordia> :O
<holborn> yo llegue a trabajar programando sintes en un estudio de grabacion …. vaya no todos los dias pero me llamaban de vez en cuando
<holborn> haciendo presets … me refiero .. claro
<hordia> veo que horgand es el resultado de muchos años de experiencia…
<holborn> si … a ese nivel si … pero todo fue gracias a un ejemplo de la web de alsa .. .se llama fmminisynth.c … o lago asi … 100 lineas de codigo … entonces se me ocurrio … y empece ..

<holborn> luego buscando … encuentras mil ejemplos de codigo … en HArmony Central … no esta el codigo pero explican como funcionan los efectos … en cristiano .. sin mucha matematica … esta muy bien .. luego ya el implementarlo es cosa de uno … pero el mismo Paul Nasca dice por ahi (el del zyn) que se basa en esa explicaciones … y yo tambien claro :)
<holborn> ya te aseguro que su implementacion es mejor que la mia :)
<hordia> jeje
<holborn> ahora …la mia consume un tercio de cpu que la suya :)
<hordia> entonces hay que ver que parametros se toman para definir cual es mejor ;-)
<holborn> pues es un sinte … lo que suena … sus efectos suenan mejor …. pero … el usa 3 o 4 osciladores por sonido … yo uso 20 … con lo cual en algun lado hay que recortar …

El ejemplo que se menciona: miniFMsynth.c


, , , , , , , , , , ,

Posted in audio, algorithms, effects, free software, programming, instruments, GNU/Linux, GPL, c++, alsa, Castellano, sound | No Comments »

LADSPA versions of my recent simple distortions

Posted by hordia on 17th December 2007

After prototype different kind of simple distortions in NetworkEditor i managed to port all them to ladspa plugins. Despite the fact that the task was less difficult than i had expected at first, prototype with CLAM first worth a lot. Probably, if i had begun coding directly to ladspa source, reach the same status would be taken to me 10 or more times more. I think also was very interesting as “development process”, instead of modeling for example with matlab, you could easy modeling (among other things) in CLAM, and then, if you want/need make your final product by your own.

More, the other day i learned that is already possible to compile ladspa plugins directly from CLAM networks… very cool! Though i think this feature is not completely ready yet and i’m still have to dig in it, i don’t think that i have lost time porting manually because now i have a better knowledge and understanding about ladspa specification that for sure will be useful to work with this (for me “new”) feature, that probably needs some fixes.

About the ladspa plugins programming, i just downloaded the sdk from ladspa.org, read some of the ladspa.h file and some basic examples (the ones from sdk) and that was enough to handle the basis. Ah, i had to ask for some ladspa ID’s for my plugins here: ladspa at muse.demon.co.uk

On the other hand i’ve forwarded my distortion examples to musix distro folks and some of them indeed have tried it and made a couple of jack-rack presets and audio demos. More info about this here: DSP-es#Presets, ogg demos and jack-rack presets, and patchs review.

Next step (in my TODO list): produce ladspa binaries directly from CLAM networks.

I have uploaded these plugins here: disthordian ladspa plugins.


, , , , , , , , , ,

Posted in audio, algorithms, effects, free software, programming, c++, libraries, English, CLAM, plugins, specifications | No Comments »

New CLAM plugin: (’very’ for now) simple guitar distortion

Posted by hordia on 9th December 2007

A week or more ago, Daniel Vidal Chornet (collaborator of Musix) asked me if i can develop guitar distortion effects, because he couldn’t find something decent that suits his needs, i said “sadly i have no idea about distortions effects and anyway i have no time right now to do that”, but then i remembered how useful could be the clam framework and i tried to do a little spike about. Results were better than i had expected at first (is not a super cool distortion, but at least sound like one).

Basically i merged and tweaked a couple of simple/base algorithms found in the web for distortion and compression and in less than 30 minutes i had something working and sounds like a guitar distortion (”clean” ones seems to sound better easily). I was amazed how fast and easy (develop and test in clam/networkeditor, once you get the basis) was. I think right now is far to be a good distortion, but as learning process and first demo seems very good.

Here some sound examples:

Original:
(dvlc-guitar.ogg)

With distortion:
(guitardist-ex1.ogg)

Test network looks like:

Distortion NE network

 

The source code is here (as NetworkEditor plugin): GuitarDistortion.tar.gz

Some optional tweaks could include add a three band filter but i’m still not sure if it’s better to put it at first or at the end.

Special thanks for testing and audio samples to Daniel Vidal Chornet. I should take from my closet my fender stratocaster and do my own samples :-D . OTOH, we already arrange to do a remote gig with this.

Another useful NetworkEditor processings plugins i had made during this “work”:

  • AutomaticGainControl: Adaptative automatic gain control. Given an output reference and step response adjusts the output volume to keep it constant (AutomaticGainControl.tar.gz)
  • AudioSwitch: Switchs between a configurable amount of inputs (like a multiplexer) (AudioSwitch.tar.gz)

 
Related: LADSPA versions of my recent simple distortions
Update: Distortion rack prototype


, , , , , , , , , ,

Posted in audio, algorithms, effects, free software, programming, GPL, c++, English, CLAM, plugins, library | 6 Comments »

My presentation at the “VI Jornadas de Acústica, Electroacústica y áreas vinculadas (CADAE)”

Posted by hordia on 27th October 2007

Yesterday I had the opportunity to give a talk about my recent work in the google summer of code at the VI Jornadas de Acústica, Electroacústica y áreas vinculadas (CADAE). The given time was short, so was a little hard to explain all in only 20 minutes, but seems that all went well (at least seemed like the people). Here my presentation (in Spanish):

 

Transformaciones espectrales en tiempo real para CLAM

 

Download: Transformaciones espectrales en tiempo real para CLAM.pdf

 


, , , , , , , , , , , , , , , , , ,

Posted in audio, acoustics, algorithms, effects, signal processing, free software, programming, GPL, c++, libraries, midi, English, CLAM, GSoC2007, GUI, talks, dissertation, events, conferences | No Comments »

Presentación en las VI Jornadas de Acústica, Electroacústica y áreas vinculadas (CADAE)

Posted by hordia on 27th October 2007

Ayer tuve la oportunidad de presentar mi trabajo realizado para el google summer of code en el marco de las VI Jornadas de Acústica, Electroacústica y áreas vinculadas (CADAE), les dejó la presentación de la misma:

 

Transformaciones espectrales en tiempo real para CLAM

 

Download: Transformaciones espectrales en tiempo real para CLAM.pdf


, , , , , , , , , , , , , , , , , , , , , ,

Posted in audio, acoustics, algorithms, effects, signal processing, music, free software, programming, GNU/Linux, GPL, open source, c++, libraries, midi, python, projects, Castellano, CLAM, GSoC2007, GUI, talks, dissertation, conferences | No Comments »

Fundamental (in Hz) to a MIDI note

Posted by hordia on 26th August 2007

Working to have audio-to-midi in NetworkEditor (CLAM) I needed to convert a fundamental frequency value to a MIDI note one.

I found some source code related with this in Voice2MIDI app, but was not explained at all, so looking for the reason of that formula I arrived at this:

Knowing about equal-tempered scale (check this) and 2^{\frac{n}{12}} relation between frequencies plus the fact that C4 or “middle c” has a MIDI value of 60, it’s easy to conclude that then A4 (which its frequency value is 440Hz, a standard for tunning and is 9 semi-tones more) has a MIDI value of 69.

 

Then, starting with:
fundfrec = 440Hz * 2^{(\frac{1}{12})^n}

 

It’s easy to arrive at this:
fund_{midinote} = 69+log_{2^{(\frac{1}{12})}}(\frac{fundfrec}{440Hz})

 

and then, also taking in account this mathematical relation::
log_{2^{\frac{1}{12}}}(a) = log_{e}(a)*17.31234

 

the final formula looks like:
fund_{midinote} = 69+log_{e}(\frac{fundfrec}{440Hz})*17.31234

 

and a final c++ code like:

fund_midinote = round( 69. + log(fundfrec/440.)*17.31234 );

 
Related post: nictuku’s inverse formula (i.e. from MIDI to Hz) here “Translanting MIDI Notes to frequencies in the diatonic scale using the central A (440hz) as reference“.


, , , , , , , , , ,

Posted in audio, algorithms, programming, music theory, c++, midi, math, English, CLAM, standards, GSoC2007 | No Comments »

Trabajar con wavs de 8 bits en python

Posted by hordia on 6th August 2007

Hace un tiempo escribí un par de funciones para trabajar con wavs en python como si fuesen vectores, es decir, al “estilo” matlab (para más detalles ver este post “Funciones para trabajar con wav’s vectorialmente en python“).

Casualmente en la misma semana 2 personas, Cesar Perez (Colombia) y Elizabeth Coixet (España), me escribieron a este blog comentandome que estaban usando mis funciones con éxito pero tenian problemas al leer wav’s de 8 bits. Les recomendé que lo charlaramos en el grupo Buena Señal ya que entre todos (y posiblemente alguna contribución de alguno más de los del grupo) seguramente iba a ser más fácil y todos podriamos aprender algo de ello (ver estos 2 threads: 1, 2).

Y asi fue :-)

Luego de que Cesar planteara el problema y yo hiciese mis apreciaciones sobre el asunto, Elizabeth encontró que el wav de 8 bits era unsigned y no signed (como el de 16 bits) con lo que se termino de resolver el misterio de porque la solución que manejabamos leia en forma extraña…

Bueno la función queda asi:

# Example: [ y, Fs, bits ] = wavread8bits( 'filename' )
def wavread8bits( name ):
	file = wave.open( name, 'r' )
	[Channels,Bytes,Fs,Frames,Compress,CompressName] = file.getparams() # (nchannels, sampwidth in bytes, sampling frequency, nframes, comptype, compname)
	Bits = Bytes*8 # 8 bits per sample
	Data = file.readframes( Frames )
	Data = (fromstring( Data, UInt8 ) / 128.0 ) - 1.0 # -1..1 values
	print "Fs: ",Fs,"\nBits: ",Bits,"\nChannels: ",Channels
	file.close()
	return Data, Fs, Bits

 
De paso también escribí la función para escribir un wav de 8 bits.

# Example: wavwrite8bits( y, Fs, filename )
def wavwrite8bits( data_array, Fs, name ):
	file = wave.open( name, 'w' )
	file.setframerate( Fs ) # sets sampling frequency
	file.setnchannels( 1 ) # sets number of channels
	file.setsampwidth( 1 ) # number of bytes, 8 bits per sample
 
	clipped = False
	block_size = 1024*10 # write block size: 10k
	a_max = 255 # max amp
	a_min = 0 # min amp
	n = 0
	len_data_array = len( data_array ) # 1 byte (UInt8) data
	while n < len_data_array :
		frame = '' # string frame of 'block_size'
		for i in range( block_size ) :
			if n < len_data_array :
				newbyte = int( (data_array[n]+1.0) * 128 ) # ~ 255/2
				if newbyte > a_max or newbyte < a_min : clipped = True
				newbyte = min( max(newbyte,a_min), a_max ) # normalization, 0..255
				#newbyte.clip( min=a_min, max=a_max ) # normalization, 0..255
				frame += chr( newbyte & 0xFF ) # takes the byte, converts it to char and adds it to the frame
				n += 1
		file.writeframes( frame )
	if clipped == True : print "Warning: Some values were clipped"
	print "Final length:", len_data_array/512,"kb" # n*2/1024 (bytes size/1024) = n/512
	file.close()

El archivo con todas estas funciones de lectura/escritura (8 y 16 bits) es este: wav_array.py

Gracias a todos!


, , , , , ,

Posted in audio, algorithms, programming, GPL, formats, python, Castellano | No Comments »

SMSMorph part1

Posted by hordia on 6th August 2007

Morph effect (best know in images domain) it’s about hybridize two sounds so the resulting one has intermediate characteristics. This implementation is mainly based on interpolation (peaks and residual spectrum) and a balance (depending on interpolation factor) of fundamental.

All the code is mainly based on this idea: (1. - alpha)*FirstSound + alpha*SecondSound, where alpha is the interpolation factor (bounded to 0..1 range).

SMSMorph Network

 
I’m still have to tweak it a bit… but anyway I’ve made some demos of it:

Sources: Piano C5 and Oboe C5.
Demos: Take 1, Take 2
To hear the online/streaming version go here.

Samples were taken from Freepats / Iowa Musical Instruments Samples.


, , , , , , ,

Posted in audio, algorithms, effects, signal processing, programming, English, CLAM, GSoC2007 | No Comments »

SMS Harmonizer part1

Posted by hordia on 31st July 2007

I’ll start talking a bit about this effect which is mainly used for vocal harmonizing. Given an input voice (or whatever) as output you obtain (how many as you want) automatic harmonic related voices (a minor/major third, a fifth, a sixth or any musical interval you want).

This implementation, is mainly based on many SMS pitch-shiftings (one for each voice) and a control gain for each one. Pitch controls are based on equal-tempered scale semitones, following fund*2^{\frac{p_c}{12}} relation for each voice.

 
This was my first version of the network:

SMSHarmonizer-basic-network

 
 
Testing it, my voice never sounded so musical, hehehe… but still awful, so I was thinking in your ears health and demos are with Elvis one ;-)

Disclaimer: all audio demos are early testing versions (still with artifacts and clicks that should be removed soon)

Elvis harmonized demo: elvis-harmonized.ogg (to hear the online/streaming version go here)

 
Prototype:

harmonizer prototype

 
 
Configuration:
SMSHarmonizer config

Note: demos were done without residual processing because adding residual does not improve results much and adds a lot of overhead.

 
 
Then, following xamat’s suggestions I also added a detunning effect (and delay, but this one isn’t working properly yet)

SMSHarmonizer detuning delay

 
 
Elvis harmonized (detunned version) demo: elvis-harmonized-detunned.ogg (to hear the online/streaming version go here)

 
but wait! a lot of graphics and this is also a ‘coding’ blog!!! here you have some code… and btw you can see that programming under CLAM could be very easy once you get the basics…

bool SMSHarmonizer::Do( const SpectralPeakArray& inPeaks, 
			const Fundamental& inFund,
			const Spectrum& inSpectrum, 
			SpectralPeakArray& outPeaks,
			Fundamental& outFund,
			Spectrum& outSpectrum
		      )
{
	outPeaks = inPeaks;
	outFund = inFund;
	outSpectrum = inSpectrum;
 
	TData gain0 = mInputVoiceGain.GetLastValue();
	mSinusoidalGain.GetInControl("Gain").DoControl(gain0);
	mSinusoidalGain.Do(outPeaks,outPeaks);
 
	SpectralPeakArray mtmpPeaks;
	Fundamental mtmpFund;
	Spectrum mtmpSpectrum;
 
	for (int i=0; i < mVoicesPitch.Size(); i++)
	{
		TData gain = mVoicesGain[i].GetLastValue();
		if (gain&lt;0.01) //means voice OFF
			continue;
		
		TData amount = mVoicesPitch[i].GetLastValue() + frand()*mVoicesDetuningAmount[i].GetLastValue(); //detuning
		amount = CLAM_pow( 2., amount/12. ); //adjust to equal-tempered scale semitones
 
		mPitchShift.GetInControl("PitchSteps").DoControl(amount);
		mPitchShift.Do( inPeaks,
				inFund, 
				inSpectrum,
				mtmpPeaks, 
				mtmpFund,
				mtmpSpectrum);
	
		mSinusoidalGain.GetInControl("Gain").DoControl(gain);
		mSinusoidalGain.Do(mtmpPeaks,mtmpPeaks);
 
		TData delay = mVoicesDelay[i].GetLastValue();
		if (delay>0.)
		{
			mPeaksDelay.GetInControl("Delay Control").DoControl(delay);
			mPeaksDelay.Do(mtmpPeaks, mtmpPeaks);
		}
 
		outPeaks = outPeaks + mtmpPeaks;
		
		if (!mIgnoreResidual)
			mSpectrumAdder.Do(outSpectrum, mtmpSpectrum, outSpectrum);
	}
	return true;
}

The plan includes add MIDI control for each voice pitch (then will be easy to control them for example by a keyboard by the same singing person)

Next post: SMSMorph.


, , , , , , , , , , , ,

Posted in audio, algorithms, effects, signal processing, programming, music theory, c++, midi, math, English, CLAM, GSoC2007, GUI | 1 Comment »

 
Cerrar
Enviar por Correo