News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

FIR Audio Spectrum Analyzer

Started by Siekmanski, September 03, 2014, 10:14:36 PM

Previous topic - Next topic

Siekmanski

Found 2 bugs in my code.
There was a buffer overrun when calculating the frequency bands. ( corrected this )
And something very stupid, i was only calculating the left audio channel. ( corrected this )
I blame it on my motorcycle accident.  :biggrin:

New source code and executable in first post.
Creative coders use backward thinking techniques as a strategy.

dedndave


Gunther

You have to know the facts before you can distort them.

guga

Hi marinus

can you make it export the audio ?
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

Siekmanski

Yes, but the exported audio file would be the same as the imported file.
The sound isn't altered.
Creative coders use backward thinking techniques as a strategy.

guga

Hmm, and how to make it be altered ? Export the result without having to play the whole file ? (I mean, like when you load a file in audacity and pass a filter, then export the resultant file)
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

dedndave

oops - posted in the wrong thread - lol

Siekmanski

Hi guga,
You can do that with the filter routines of the FIR analyzer.
But the program has to be completely rewritten.
You have to implement something like a WAV-writer routine to save the filtered audio.
Do you need an example of a WAV-writer routine ?
Creative coders use backward thinking techniques as a strategy.

Siekmanski

Hi Dave,
Quotewhat might be fun would be to feed audio into it, and draw a graph of the output   :biggrin:

Do you mean a spectrum waterfall graph ?
Creative coders use backward thinking techniques as a strategy.

dedndave

yah - i meant to post in the other thread on FFT, though
i was thinking spectrum analyzer, of course

with a mixer, it could even be used for frequencies above audio (not an audio mixer)
but, not a lot of bandwidth to work with - it could be stepped to increase the apparent bandwidth

guga

Hi marinus,

If you can, send me an example of wav-writer routine. Your filter is excelent for audio i have that needs a cleanup. I was thinking in using it 1st before i use other apps to remove clicks, noises etc.

I´m curious what the filter should do with a noisy audio file. If it attenuates the noise and enhance the vocals, then another app can better remove the noises completely.

Your routines needs to be used directly in the audio data, right ?

Or perhaps, writting a vst plugin for audacity would be also a good idea
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

Siekmanski

Hi guga,

QuoteYour routines needs to be used directly in the audio data, right ?

You can use the filter routines for any type ( as long it is float 32 bit ) of data, realtime or read a file and filter that data if you want.

There is a free online DSP course at Coursera (Stanford University).
The title is Audio Signal Processing for Music Applications.

Here you can sign in for free: http://coursera.org/course/audio

You can learn a lot, it's a great course.

I'll post the routine today.


Creative coders use backward thinking techniques as a strategy.

Siekmanski

Hi guga,

here the wav-writer routine

.data

Wave_Header     db "RIFF"
Wave_Length     dd 0        ; sample data length + (44 - 8)
                db "WAVE"
                db "fmt "
                dd 16       ; format chunk size
Wave_Encoding   dw WAVE_FORMAT_PCM
Wave_Channels   dw 0
Wave_Samplerate dd 0
Wave_BPS        dd 0
Wave_Blockalign dw 0
Wave_SampleBits dw 0
                db "data"
Wave_Datalength dd 0

Filename    "Dance.wav",0
.code
WriteAudio_2_WAV proc
    LOCAL   hFileOut,dwBytesDone:DWORD
   
    invoke  CreateFile,addr Filename,GENERIC_WRITE,NULL,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
    inc     eax
    jz      close
    dec     eax
    mov     hFileOut,eax

    invoke  SetFilePointer,hFileOut,44,0,FILE_BEGIN

Writeloop:
;   get your audio data from the audiobuffer here with your own routine
;   data must be 16bit interleaved
   
    invoke  WriteFile,hFileOut,AudioBuffer,AudioLength,addr dwBytesDone,0

;   jump to Writeloop till done

;   Now prepare the WAV header:
;   This example is for a 2 channel 16bit 44100 Hz wav-file

    mov     eax,44100
    mov     Wave_Samplerate,eax
    mov     cx,2
    mov     Wave_Channels,cx
    shl     eax,cl
    mov     Wave_BPS,eax
    shl     ecx,1
    mov     Wave_Blockalign,cx
    mov     Wave_SampleBits,16

    mov     eax,TotalbytesWritten
    mov     Wave_Datalength,eax
    add     eax,36
    mov     Wave_Length,eax     ; sample data length + (44 - 8)

;   now write the WAV header
    invoke  SetFilePointer,hFileOut,0,0,FILE_BEGIN
    invoke  WriteFile,hFileOut,addr Wave_Header,44,addr dwBytesDone,0
close_file_out:
    .if ( hFileOut )
        invoke  CloseHandle,hFileOut
    .endif

    mov     eax,TRUE
    ret
WriteAudio_2_WAV endp
Creative coders use backward thinking techniques as a strategy.

guga

Thanks Marinus. I´ll give it a try.

A few things. I´m analyzing the results of the FIR file using Audacity to record it.

Your FIR is excellent to remove DCoffsets and normalize the audio data as shown in the image below (the 1s track is the file using FIR. The 2nd is the original file)

Awesome Normalization



Problems:
I tested it to see either it was a problem in Audacity´s Recorder or FIR demo. The problem is with the demo. It is breaking the audio data in some places.(I opened the "untouched" file and listened to it. It is cracking the sound wave.

The sound track under FIR was "breaked" in a couple of points, and it extended the length by 2 secs

Fig1: Cracked data



Fig2: Extended time


Do you want me to send to you the audio file to test ?
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

guga

Dispites the cracking. The resultant data after using a noise remover (I used IzotopeRX for that) is really awesome. (I passed the Noise remover only twice)

Btw....do you have any idea how to remove/reduce noise using a pattenr ? (as in audacity/IzotopeRX) ? It would be an very good idea implement it with the Demo, since it is doing an amazing job in Normalizing the wave data. (also a click remover would be good too)

Take a look, how clean became the file after using the noise remover on the resultant file generated with FIR.



I´m amazed. The sound "looks" incredible. No muffing or robotic sound whatsoever. (Only the cracking needs a fix)
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com