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

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



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 3169 times)
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

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


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

on Aug 7th, 2014, 2:51pm, James wrote:
I couldn't get any success.

Did it not work at all (which would surprise me) or did it work but only at 22050 Hz sampling (which is probably to be expected)?

Whenever I've done audio recording I've used the lower-level waveIn API functions, which seem to work fine at 44100 Hz, but of course are rather more complicated to get going. I have BBC BASIC code (which in principle could be run in LBB using the 'translator bypass' feature) but I've never tried to do it in Liberty BASIC.

If you want to find out whether it would work, you can try running this BBC executable.

Richard.
User IP Logged

James
New Member
Image


member is offline

Avatar




PM


Posts: 42
xx Re: Recwave "talking.wav", 44100 / Stopr
« Reply #16 on: Aug 11th, 2014, 4:11pm »

Wow, Mr. Russel, this seems to work fine! Sorry for the delay, I was finally able to test it on something besides XP. That would be great if we could use this ability in Liberty Basic!
« Last Edit: Aug 11th, 2014, 4:14pm by James » User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Recwave "talking.wav", 44100 / Stopr
« Reply #17 on: Aug 14th, 2014, 1:33pm »

on Aug 11th, 2014, 4:11pm, James wrote:
That would be great if we could use this ability in Liberty Basic!

One of the problems is that the BBC BASIC code uses an array-of-structures, and sadly Liberty BASIC doesn't support arrays of structures. sad

If I get a chance I will look into the possibility of using a kludge to resolve this issue.

Richard.
User IP Logged

James
New Member
Image


member is offline

Avatar




PM


Posts: 42
xx Re: Recwave "talking.wav", 44100 / Stopr
« Reply #18 on: Aug 15th, 2014, 06:24am »

Thanks very much! grin
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Recwave "talking.wav", 44100 / Stopr
« Reply #19 on: Aug 15th, 2014, 12:04pm »

Try this. It records 44100 Hz stereo to a WAV file; I've tested it with LBB 2.64 on Windows XP, 7 and 8.1. There is no source selection or setting of level, you will need to do that in Control Panel (Sound... Recording...). If you develop this into something amazing, I would appreciate an acknowledgement of my contribution. Enjoy!

Code:
    ' Audio recorder (c) Richard Russell, 15-Aug-2014
    nomainwin
    global record.flag, record.buff, wavfile$

    filedialog "Save WAV file", "*.wav", wavfile$
    if wavfile$ = "" then end

    button #w.start, "Start Recording", startrec, UL, 100, 100
    button #w.stop, "Stop Recording", stoprec, UL, 100, 200
    open "Audio recorder" for window as #w
    #w "trapclose quit"
    #w.stop "!disable"
    call record.init
    timer 50, record.poll
    wait

sub quit handle$
    timer 0
    call record.exit
    close #w
    end
end sub

sub startrec handle$
    #w.start "!disable"
    #w.stop "!enable"
    call record.start wavfile$
end sub

sub stoprec handle$
    call record.stop
    #w.stop "!disable"
    #w.start "!enable"
end sub

sub record.init
    ' Initialise the wave input format:
    struct waveFormatEx, _
        wFormatTag as word, nChannels as word, nSamplesPerSec as ulong, _
        nAvgBytesPerSec as ulong, nBlockAlign as word, _
        wBitsPerSample as word, cbSize as word

    waveFormatEx.wFormatTag.struct = _WAVE_FORMAT_PCM
    waveFormatEx.nChannels.struct = 2 
    waveFormatEx.nSamplesPerSec.struct = 44100
    waveFormatEx.wBitsPerSample.struct = 16
    waveFormatEx.nBlockAlign.struct = waveFormatEx.nChannels.struct * waveFormatEx.wBitsPerSample.struct / 8
    waveFormatEx.nAvgBytesPerSec.struct = waveFormatEx.nSamplesPerSec.struct * waveFormatEx.nBlockAlign.struct

    ' Create wave headers:
    struct WAVEHDR, lpData as ulong, dwBufferLength as ulong, _
        dwBytesRecorded as ulong, dwUser as ulong, dwFlags as ulong, _
        dwLoops as ulong, lpNext as ulong, Reserved as ulong

    ' Fill in wave headers, allocate, prepare and add buffers:
    BytesPerBuffer = 16384

    struct WaveIn, hndl as ulong
    calldll #winmm, "waveInOpen", WaveIn as struct, _WAVE_MAPPER as long, _
        waveFormatEx as struct, 0 as long, 0 as long, _
        0 as long, ret as long
    if ret then notice "waveInOpen failed" : end

    for buff = 0 TO 7
        h = WaveIn.hndl.struct
        l = len(WAVEHDR.struct)

        ' Kludge to fake array of structures:
        calldll #kernel32, "GlobalAlloc", _GMEM_FIXED as long, _
            l as ulong, header as ulong
        calldll #kernel32, "GlobalAlloc", _GMEM_FIXED as long, _
            BytesPerBuffer as ulong, buffer as ulong
        Headers(buff) = header
        WAVEHDR.lpData.struct = buffer
        WAVEHDR.dwBufferLength.struct = BytesPerBuffer
        WAVEHDR.dwFlags.struct = 0
        calldll #kernel32, "RtlMoveMemory", header as ulong, _
            WAVEHDR as struct, l as ulong, ret as long

        calldll #winmm, "waveInPrepareHeader", h as ulong, _
            header as ulong, l as ulong, ret as long
        if ret then notice "waveInPrepareHeader failed" : end
  
        calldll #winmm, "waveInAddBuffer", h as ulong, _
            header as ulong, l as ulong, ret as long
        if ret then notice "waveInAddBuffer failed" : end
      next

      record.buff = 0
      calldll #winmm, "waveInStart", h as ulong, ret as long
      if ret then notice, "waveInStart failed" : end
end sub

sub record.start filename$ 
    open filename$ for output as #recordfile
    format$ = waveFormatEx.struct
    print #recordfile, "RIFF";
    print #recordfile, d4$(0); ' Filled in later
    print #recordfile, "WAVE";
    print #recordfile, "fmt ";
    print #recordfile, d4$(16);
    print #recordfile, left$(format$,16);
    print #recordfile, "data";
    print #recordfile, d4$(0); ' Filled in later
    seek #recordfile, 44
    record.flag = 1
end sub

sub record.stop
    record.flag = 0
    size = lof(#recordfile)
    seek #recordfile, 4
    print #recordfile, d4$(size - 8);
    seek #recordfile, 40
    print #recordfile, d4$(size - 44);    
    seek #recordfile, size
    close #recordfile
end sub

sub record.exit
    h = WaveIn.hndl.struct
    calldll #winmm, "waveInStop", h as ulong, r as long
    calldll #winmm, "waveInReset", h as ulong, r as long
    for i = 0 to 7
        header = Headers(i)
        WAVEHDR.struct = header
        h = WaveIn.hndl.struct
        l = len(WAVEHDR.struct)
        p = WAVEHDR.lpData.struct
        calldll #winmm, "waveInUnprepareHeader", h as ulong, _
            header as ulong, l as ulong, r as long
        calldll #kernel32, "GlobalFree", p as ulong, r as long
        calldll #kernel32, "GlobalFree", header as ulong, r as long
    next i
    calldll #winmm, "waveInClose", h as ulong, r as long
end sub

sub record.poll
    header = Headers(record.buff)
    WAVEHDR.struct = header
    if WAVEHDR.dwFlags.struct and _WHDR_DONE then
        WAVEHDR.dwFlags.struct = WAVEHDR.dwFlags.struct and (-_WHDR_DONE-1)
        if record.flag then
            h = hwnd(#recordfile)
            d = WAVEHDR.lpData.struct
            l = WAVEHDR.dwBytesRecorded.struct
            struct written, n as ulong
            calldll #kernel32, "WriteFile", h as ulong, d as ulong, _
                l as ulong, written as struct, 0 as ulong, r as long
        end if
        h = WaveIn.hndl.struct
        l = len(WAVEHDR.struct)
        calldll #winmm, "waveInAddBuffer", h as ulong, header as ulong, _
            l as ulong, r as long
    record.buff = (record.buff + 1) mod 8
    end if
end sub

function d4$(n)
    a = n mod 256
    n = int(n/256)
    b = n mod 256
    n = int(n/256)
    c = n mod 256
    n = int(n/256)
    d = n mod 256
    d4$ = chr$(a)+chr$(b)+chr$(c)+chr$(d)
end function 

Richard.
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