Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What options are there to get audio input?
#1
I was wondering what are different ways to get audio line/mic input in a QB64PE program.  I know there is Windoes API.  Is there a way in Linux?

- Dav

Find my programs here in Dav's QB64 Corner
Reply
#2
We actually already have the capability to do it in a cross-platform manner.

Suggest what you think would work for you. We can discuss the API and have it in a future release.

Since audio input is going to be continuous stream, my suggestion is something that works like a reverse _SNDRAW. What do you think?

receivedFrames& = _SNDINPUT&(inputArray!(), channels&, requestedFrames&)

Something like that?

I was also thinking of a cross-platform MIDI I/O.  Big Grin
Reply
#3
Oh cool, I didn’t know it already existed. _SNDINPUT sounds great.  I tune pianos on the side, always wished to make a tuner app. Also, since QB64PE can play multiple waves simultaneously, having a Line/mic recording method would be all that’s needed to have a multitrack recorder program going.  

Kinda just dreaming on those 2 things, but recording audio in QB64PE is something that would really round off QB64PE’s great audio capabilities.

- Dav

Find my programs here in Dav's QB64 Corner
Reply
#4
You can get sound input from the MCI API in Win32. Here's some old code I made a long time ago when I was maintaining the "Spriggsy's API Collection" repo.

Code: (Select All)
OPTION _EXPLICIT

_TITLE "mciSendString Record Test"

StartRecording
DIM x
DIM y

x = TIMER(0.01)
DO
    y = TIMER(0.01)
    CLS
    PRINT "Recording...Press any key to stop"
    PRINT y - x
    _DISPLAY
LOOP UNTIL INKEY$ <> ""

StopRecording
SaveRecording ("test.wav")
PlayRecording ("test.wav")

'_TITLE "Waveform Display"
'SCREEN GetWaveform("test.wav", "640x480")


DECLARE DYNAMIC LIBRARY "WINMM"
    FUNCTION mciSendStringA% (lpstrCommand AS STRING, lpstrReturnString AS STRING, BYVAL uReturnLength AS _UNSIGNED LONG, BYVAL hwndCallback AS LONG)
    FUNCTION mciGetErrorStringA% (BYVAL dwError AS LONG, lpstrBuffer AS STRING, BYVAL uLength AS _UNSIGNED LONG)
END DECLARE

SUB StartRecording
    DIM a AS LONG
    a = mciSendStringA("open new type waveaudio alias capture" + CHR$(0), "", 0, 0)
    IF a THEN
        DIM x AS INTEGER
        DIM MCIError AS STRING
        MCIError = SPACE$(255)
        x = mciGetErrorStringA(a, MCIError, LEN(MCIError))
        PRINT MCIError
        END
    ELSE
        a = mciSendStringA("set capture time format ms bitspersample 16 channels 2 samplespersec 48000 bytespersec 192000 alignment 4" + CHR$(0), "", 0, 0)
        a = mciSendStringA("record capture" + CHR$(0), "", 0, 0)
    END IF
END SUB

SUB StopRecording
    DIM a AS LONG
    a = mciSendStringA("stop capture" + CHR$(0), "", 0, 0)
END SUB

SUB SaveRecording (file AS STRING)
    DIM a AS LONG
    a = mciSendStringA("save capture " + CHR$(34) + file + CHR$(34) + CHR$(0), "", 0, 0)
    a = mciSendStringA("close capture" + CHR$(0), "", 0, 0)
END SUB

SUB PlayRecording (file AS STRING)
    DIM a AS LONG
    a = mciSendStringA("play " + CHR$(34) + file + CHR$(34) + CHR$(0), "", 0, 0)
END SUB

'FUNCTION GetWaveform& (file AS STRING, size AS STRING)
'    IF _FILEEXISTS("output.png") THEN
'        KILL "output.png"
'    END IF
'    SHELL _HIDE "ffmpeg -i " + CHR$(34) + file + CHR$(34) + " -filter_complex " + CHR$(34) + "showwavespic=s=" + size + CHR$(34) + " -frames:v 1 output.png"
'    GetWaveform = _LOADIMAGE("output.png", 32)
'END FUNCTION
Tread on those who tread on you

Reply
#5
Hey thanks, @SpriggsySpriggs. Yes I remember you sharing that. Was going to look for that in my saved files, now I don’t have too.   Wink

 - Dav

Find my programs here in Dav's QB64 Corner
Reply
#6
Hey @SpriggsySpriggs, just thought I'd mention that your win api recorder code up there works fine in the windows version of qb64pe running under linux using wine.

- Dav

Find my programs here in Dav's QB64 Corner
Reply
#7
Nice. Wine is truly a wonderful thing. Even my video player works a little bit in it.
Tread on those who tread on you

Reply




Users browsing this thread: 1 Guest(s)