LB Booster
« Recwave "talking.wav", 44100 / Stoprec »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 03:28am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 veryhotthread  Author  Topic: Recwave "talking.wav", 44100 / Stoprec  (Read 3165 times)
James
New Member
Image


member is offline

Avatar




PM


Posts: 42
xx Recwave "talking.wav", 44100 / Stoprec
« Thread started on: Jul 7th, 2014, 2:37pm »

Thanks Richard for all the hard work!

It would be neat to be able to start/stop recording audio like this:

[recbutton]
Recwave "singin.wav", 44100
wait

[stopbutton]
Stoprec
wait

I haven't been able to record audio very well in vista. embarassed

------------

Rom. 1:16) For I am not ashamed of the gospel of Christ: for it is the power of God unto salvation to every one that believeth;
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Recwave "talking.wav", 44100 / Stopr
« Reply #1 on: Jul 7th, 2014, 5:46pm »

on Jul 7th, 2014, 2:37pm, James wrote:
It would be neat to be able to start/stop recording audio like this: Recwave "singin.wav", 44100

Using the mciSendString API is nearly as simple, isn't it? I think I'm right in saying that you only need to send three commands to start recording audio to a file:

"open new type waveaudio alias capture"
"set capture parameters"
"record capture"

Then to stop the recording:

"stop capture"
"save capture filename"
"delete capture"
"close capture"

As far as I know this technique works in 'modern' versions of Windows, but I can't say I've actually tried it.

Richard.
User IP Logged

Rod
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 110
xx Re: Recwave "talking.wav", 44100 / Stopr
« Reply #2 on: Jul 8th, 2014, 6:36pm »

This code shows some of the mci command strings in use. It works on LBB Win8.1


Code:
 'this records saves and loads 1.5 second long
        'audio as 8bit .wav files it runs at
        '11025 samples per second for 1.5 seconds = 16537 samples
        'in each file. samples range from 0 to 255
        true=1
        false=0
        recording=false   ' are we recording right now or not?
        mid=127
        sampos=45

        WindowWidth = 800
        WindowHeight = 600
        UpperLeftX=int((DisplayWidth-WindowWidth)/2)
        UpperLeftY=int((DisplayHeight-WindowHeight)/2)



        nomainwin
        graphicbox #main.current, 130,   5, 630, 256
        graphicbox #main.library, 130, 266, 630, 256
        button #main.record,"Record",[record], UL,   5,   7,  90,  25
        button #main.save,"Save",[save], UL,   5,  37,  90,  25
        button #main.load,"Load",[load], UL,   5,  67,  90,  25
        button #main.play,"Play",[play], UL,   5,  97,  90,  25
        button #main.left,"<",[left], UL, 5,127,40,25
        button #main.right,">",[right], UL 55,127,40,25



        open "Sound Recording" for window as #main
        print #main.current, "down; fill darkgray; flush"
        print #main.library, "down; fill darkgray; flush"
        print #main, "font ms_sans_serif 10"


[mainloop]
        wait
        goto [mainloop]

[record]
        if recording=true then wait
        r$=mciSendString$("close all")
        r$=mciSendString$("open new type waveaudio alias capture")
        gosub [setRate]
        r$=mciSendString$("record capture")
        if r$="error" then [error]
        recording=true
        t=time$("milliseconds")
        while time$("milliseconds")<t+1500
        wend
        r$=mciSendString$("stop capture")
        r$=mciSendString$("save capture capture.wav")
        r$=mciSendString$("close capture")
        recording=false
        gosub [chart]
        wait

[play]
        if recording=true then wait
        r$=mciSendString$("open capture.wav type waveaudio alias capture")
        if r$="error" then [error]
        r$=mciSendString$("play capture wait")
        r$=mciSendString$("close capture")
        wait

[save]
        if recording=true then wait
        filedialog "Save As","*.wav",wave$
        if wave$="" then wait
        if lower$(right$(wave$,4))<>".wav" then wave$=wave$+".wav"
        r$=mciSendString$("open capture.wav type waveaudio alias capture")
        if r$="error" then [error]
        r$=mciSendString$("save capture " + wave$)
        r$=mciSendString$("close capture")
        wait

[load]
        if recording=true then wait
        filedialog "Open As","*.wav",wave$
        if wave$="" then wait
        wave$=chr$(34)+wave$+chr$(34)
        r$=mciSendString$("open " +wave$+ " type waveaudio alias capture")
        if r$="error" then [error]
        r$=mciSendString$("save capture capture.wav")
        r$=mciSendString$("close capture")
        gosub [chart]
        wait




[chart]
        xpos=0
        print #main.current, "discard ;redraw ;down"
        print #main.library, "discard ;redraw ;down"
        open "capture.wav" for binary as #live
        length=lof(#live)
        seek #live, sampos
        for n=1 to 630
        samnum=asc(input$(#live, 1))
        if samnum>mid then
        print #main.current, "color red ;size 1; line ";xpos;" ";mid;" ";xpos;" ";samnum
        else
        print #main.current, "color red ;size 1; line ";xpos;" ";samnum;" ";xpos;" ";mid
        end if
        xpos=xpos+1
        next n
        close #live
        return

[right]
        sampos=sampos+630
        if sampos>length-630 then sampos=length-630
        gosub [chart]
        wait

[left]  sampos=sampos-630
        if sampos<45 then sampos=45
        gosub [chart]
        wait


[quit]
        close #main
        end


[setRate]
        r$=mciSendString$("set capture time format ms bitspersample 8")
        r$=mciSendString$("set capture channels 1 samplespersec 11025")
        r$=mciSendString$("set capture alignment 1 bytespersec 8000")
        return


Function GetShortPathName$(lPath$)
        lPath$=lPath$+chr$(0)
        sPath$=space$(256)
        lenPath=len(sPath$)
        calldll #kernel32, "GetShortPathNameA",lPath$ as ptr,_
        sPath$ as ptr,lenPath as long,r as long
        GetShortPathName$=left$(sPath$,r)
        end function



Function mciSendString$(s$)
        buffer$=space$(1024)+chr$(0)
        calldll #winmm,"mciSendStringA",s$ as ptr,buffer$ as ptr, 1028 as long, 0 as long, r as long
        buffer$=left$(buffer$, instr(buffer$, chr$(0)) - 1)
        if r>0 then
            mciSendString$="error"
        else
            mciSendString$=buffer$
        end if
        End Function




 
User IP Logged

James
New Member
Image


member is offline

Avatar




PM


Posts: 42
xx Re: Recwave "talking.wav", 44100 / Stopr
« Reply #3 on: Jul 9th, 2014, 09:58am »

Thanks guys!

Is this code public domain? grin
User IP Logged

Rod
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 110
xx Re: Recwave "talking.wav", 44100 / Stopr
« Reply #4 on: Jul 16th, 2014, 6:27pm »

Pretty much, though it is a vast resource. It isn't specifically LBB based it is more an API scripting syntax.

http://msdn.microsoft.com/en-gb/library/windows/desktop/dd757161(v=vs.85).aspx
User IP Logged

James
New Member
Image


member is offline

Avatar




PM


Posts: 42
xx Re: Recwave "talking.wav", 44100 / Stopr
« Reply #5 on: Jul 21st, 2014, 07:20am »

It seems like Vista doesn't work with the 44100 quality mciSendString, but with the low quality. huh
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Recwave "talking.wav", 44100 / Stopr
« Reply #6 on: Jul 21st, 2014, 09:06am »

on Jul 21st, 2014, 07:20am, James wrote:
It seems like Vista doesn't work with the 44100 quality mciSendString, but with the low quality.

I don't think it's the version of Windows that matters, but the capabilities of the sound hardware and drivers you have installed on your PC.

To check what audio recording formats are available go to Control Panel... Sound... Recording... [select device]... Properties... Advanced.

Richard.
User IP Logged

James
New Member
Image


member is offline

Avatar




PM


Posts: 42
xx Re: Recwave "talking.wav", 44100 / Stopr
« Reply #7 on: Jul 21st, 2014, 2:21pm »

I don't know... huh

http://social.msdn.microsoft.com/Forums/vstudio/en-US/ba35bff1-8a3a-4a55-8cc4-24eb4f225d15/audio-capture-in-vista-defaulting-to-8-bit-pcm-wrongly-needs-to-work-in-xp-and-vista?forum=windowspro-audiodevelopment
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Recwave "talking.wav", 44100 / Stopr
« Reply #8 on: Jul 21st, 2014, 4:05pm »

on Jul 21st, 2014, 2:21pm, James wrote:
I don't know...

It's not entirely clear from that link whether they upgraded the OS without any hardware change (in which case I agree it looks like an OS issue) or whether they were running Vista on a completely different PC (in which case it could still be a hardware/driver issue).

Richard.
User IP Logged

Rod
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 110
xx Re: Recwave "talking.wav", 44100 / Stopr
« Reply #9 on: Jul 21st, 2014, 7:21pm »

Quote:
It seems like Vista doesn't work with the 44100 quality mciSendString, but with the low quality.


If you are referring to my posted code then yes it is set to low quality recording. This was to limit the data stream for analysis and display.

If you have tried to set higher quality recording and it fails then be sure you have all of the latest drivers and windows updates installed.

I would say that almost all hardware capable of running Vista is capable of recording 44k stereo audio. That's basic cd quality, most Vista+ hardware is capable of better quality.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Recwave "talking.wav", 44100 / Stopr
« Reply #10 on: Jul 22nd, 2014, 01:19am »

Are you certain that you're requesting a 'standard' set of parameters? For example Rod's code specifies 11025 Hz sampling with 8 bits-per-sample (I've corrected the bytespersec value which is incorrect in Rod's original listing):

Code:
    r$=mciSendString$("set capture time format ms bitspersample 8")
    r$=mciSendString$("set capture channels 1 samplespersec 11025")
    r$=mciSendString$("set capture alignment 1 bytespersec 11025") 

If you change only the sampling rate, to 44100 Hz, it may well not work because 8 bits-per-sample is not normal at that speed:

Code:
    r$=mciSendString$("set capture time format ms bitspersample 8")
    r$=mciSendString$("set capture channels 1 samplespersec 44100")
    r$=mciSendString$("set capture alignment 1 bytespersec 44100") 

To ensure correct operation you should specify 16 bits-per-sample:

Code:
    r$=mciSendString$("set capture time format ms bitspersample 16")
    r$=mciSendString$("set capture channels 1 samplespersec 44100")
    r$=mciSendString$("set capture alignment 2 bytespersec 88200") 

You may even find that mono recording at that sample rate is not supported, and you need to change it to stereo:

Code:
    r$=mciSendString$("set capture time format ms bitspersample 16")
    r$=mciSendString$("set capture channels 2 samplespersec 44100")
    r$=mciSendString$("set capture alignment 4 bytespersec 176400") 

Richard.
User IP Logged

James
New Member
Image


member is offline

Avatar




PM


Posts: 42
xx Re: Recwave "talking.wav", 44100 / Stopr
« Reply #11 on: Jul 22nd, 2014, 3:54pm »

Thanks Richard for your help! It seems possible that a noncompliant bytespersec value caused the same code to work fine on an XP laptop but not another VISTA laptop. shocked
User IP Logged

James
New Member
Image


member is offline

Avatar




PM


Posts: 42
xx Re: Recwave "talking.wav", 44100 / Stopr
« Reply #12 on: Jul 22nd, 2014, 6:55pm »

I can't seem to record higher than 88kbps...
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Recwave "talking.wav", 44100 / Stopr
« Reply #13 on: Jul 24th, 2014, 2:54pm »

on Jul 22nd, 2014, 6:55pm, James wrote:
I can't seem to record higher than 88kbps...

It may be that MCI imposes a limit - either to ensure reliable recording or as part of the measures taken in Windows to prevent illegal ripping of music etc.

If you're recording from the microphone or line-input, the input filter and ADC may not be capable of delivering 44100 Hz quality anyway.

Richard.
User IP Logged

James
New Member
Image


member is offline

Avatar




PM


Posts: 42
xx Re: Recwave "talking.wav", 44100 / Stopr
« Reply #14 on: Aug 7th, 2014, 2:51pm »

Chris, my friend and I were trying to record on his computer. He has a high-quality ZOOM microphone, and a high quality sound card/device, but I couldn't get any success.

It would be cool if Liberty Basic could record like it does playwave "soundfile.wav"

I need recording ability for one of my main programs, and now with XP going by the wayside, I'm trusting God to help me.
User IP Logged

Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls