Author Topic: Recording Audio in QB64?!?!  (Read 6701 times)

0 Members and 1 Guest are viewing this topic.

FellippeHeitor

  • Guest
Re: Recording Audio in QB64?!?!
« Reply #15 on: September 27, 2020, 01:21:58 am »
Done. Right now I'm adding another bit of functionality to the sound API by allowing it to show a waveform using ffmpeg :)

  [ You are not allowed to view this attachment ]  

That's cool!

Offline Richard

  • Seasoned Forum Regular
  • Posts: 364
    • View Profile
Re: Recording Audio in QB64?!?!
« Reply #16 on: September 27, 2020, 01:25:57 am »
Any use?

Quote

DECLARE DYNAMIC LIBRARY "WINMM"
    FUNCTION mciSendStringA% (lpstrCommand AS STRING, lpstrReturnString AS STRING, BYVAL uReturnLength AS INTEGER, BYVAL hwndCallback AS INTEGER)
    ' mciSendStringA function plays media files and returns the following:
    ' 0 = command sucessful
    ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    ' lpstrCommand is the MCI command string (and optional flags) to send.
    ' lpstrReturnString is a string that holds any return information.
    ' uReturnLength is the length of the lpstrReturnString string passed.
    ' NOTE: If lpstrCommand given doesn't retun a value then lpstrReturnString
    '       can be empty and uReturnLength can be set to 0.
    ' hwndCallback contains a callback window handle (only if the Notify flag used in lpstrCommand)
    '====================================================================
    FUNCTION mciGetErrorStringA% (BYVAL dwError AS INTEGER, lpstrBuffer AS STRING, BYVAL uLength AS INTEGER)
    ' mciGetErrorStringA returns error info if the mciSendStringA failed.
    ' dwError is the return value from the mciSendString function.
    ' lpstrBuffer string holds the error information returned by the function.
    ' uLength is the length of the lpstrBuffer string buffer.
    '====================================================================
END DECLARE

DECLARE CUSTOMTYPE LIBRARY
    FUNCTION FindWindow& (BYVAL ClassName AS _OFFSET, WindowName$)
END DECLARE


handle& = _NEWIMAGE(800, 600, 256)
SCREEN handle&


_TITLE "QB64 Video"
hwnd& = FindWindow(0, "QB64 Video" + CHR$(0))

ReturnString$ = SPACE$(255)
ErrorString$ = SPACE$(255)
filename$ = "c:\DavPiano.mpg" '<========== video file to play

a% = mciSendStringA%("open " + filename$ + " style popup", ReturnString$, LEN(ReturnString$), 0)

IF a% THEN
    x% = mciGetErrorStringA%(a%, ErrorString$, LEN(ErrorString$))
    PRINT ErrorString$
    END
ELSE
    a2% = mciSendStringA%("window " + filename$ + " handle " + STR$(hwnd&), ReturnString$, LEN(ReturnString$), 0)
    b% = mciSendStringA%("play " + filename$, "", 0, 0)
    _SCREENMOVE _MIDDLE
    '=== Play video...
    DO: _LIMIT 30: LOOP UNTIL INKEY$ <> ""

    x% = mciSendStringA%("stop " + filename$, "", 0, 0)
    x% = mciSendStringA%("close " + filename$, "", 0, 0)
END IF

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Recording Audio in QB64?!?!
« Reply #17 on: September 27, 2020, 01:26:54 am »
@Richard I never have been able to get that to work with any video. I'm not sure what the requirements are for codecs but I've never seen it work. I'd love to have videos play in QB64 but no luck for me.
Shuwatch!

Offline Unseen Machine

  • Forum Regular
  • Posts: 158
  • Make the game not the engine!
    • View Profile
Re: Recording Audio in QB64?!?!
« Reply #18 on: September 27, 2020, 06:07:42 am »
Oh i soooooo miss .net! We had sooooo much stuff that was lost to time! All i have now is pictures in my dropbox!

My version of mic input/playing/saving is attached but will only work with SDL .954 as the development team have yet to fix QB64 GL's ability to use linked libs. (I do hope it is gonna be fixed!)

If your looking for something to work on next, assimp or box2d would be nice (but with the affore said problems i doubt it'll be possible ( i havent figured out a waya yet!)).

Any how, nice work mr spriggs.

Unseen

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Recording Audio in QB64?!?!
« Reply #19 on: September 27, 2020, 10:36:39 am »
Thanks, @Unseen Machine !
The only issue with mciSendStringA is the quality. It is rather poor and has very little gain. You aren't able to change the input volume, either. I even tried recording desktop audio with it and it sounded horrible. I don't think there is even a way to adjust the sample rate. It's just the absolute bare necessity.
MWAHAHAHAHA that's fixed
« Last Edit: September 27, 2020, 03:50:22 pm by SpriggsySpriggs »
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Recording Audio in QB64?!?!
« Reply #20 on: September 27, 2020, 03:43:34 pm »
@Pete @Unseen Machine I finally figured out how to make it record in stereo and in a rather good quality! Here is a recording sample from myself and my desktop audio along with the waveforms generated from ffmpeg:

  [ You are not allowed to view this attachment ]  
  [ You are not allowed to view this attachment ]  

 [ You are not allowed to view this attachment ]  
  [ You are not allowed to view this attachment ]  
« Last Edit: September 27, 2020, 03:55:59 pm by SpriggsySpriggs »
Shuwatch!

Offline Unseen Machine

  • Forum Regular
  • Posts: 158
  • Make the game not the engine!
    • View Profile
Re: Recording Audio in QB64?!?!
« Reply #21 on: September 27, 2020, 06:10:01 pm »
Well done, glad you got it sorted out. Can you access the individual samples? Also, thats not what i thought youd sound like!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Recording Audio in QB64?!?!
« Reply #22 on: September 27, 2020, 06:42:30 pm »
Yes, well done! And... Weirdly enough, that's exactly what I thought you would sound like.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Recording Audio in QB64?!?!
« Reply #23 on: September 27, 2020, 07:12:36 pm »
Well done, glad you got it sorted out. Can you access the individual samples? Also, thats not what i thought youd sound like!

I don't know anything about accessing sound files, really. The waveform is a PNG that is created by ffmpeg when I pass it arguments. It would be nice to learn more about WAV files and all that.
Shuwatch!