News:

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

Main Menu

Compress MP3 files and write result to WAV container

Started by hutch--, January 13, 2022, 11:20:27 AM

Previous topic - Next topic

hutch--

While this toy is pointed at speech to get the MP3 size down, by putting a compressed MP3 file into a WAV container makes it so you can play the MP3 file with the API PlaySound(). Both the compression and conversion is done with ffmpeg and this applet is designed for drag and drop so that you can just drop an MP3 file onto it in Explorer or Winfile and it will produce a compressed WAV file.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    LOCAL pCmd  :QWORD
    LOCAL pNxt  :QWORD
    LOCAL nbuf[260]:BYTE
    LOCAL clen  :QWORD
    LOCAL fExt  :QWORD
    LOCAL eBuf[260]:BYTE

    mov pNxt, ptr$(nbuf)

    mov pCmd, rvcall(cmd_tail)                  ; get test copy of command line
    rcall szRemove,pCmd,pCmd,chr$(34)           ; remove the quotes
    rcall szRight,pCmd,pNxt,3                   ; get extension
    rcall szCmp,lcase$(pNxt),"mp3"              ; test if its mp3
    test rax, rax                               ; if 0, exit
    jnz @F
    conout lf,"Input file must be an MP3 file, either on command line OR drag and drop of MP3 file",lf
    jmp bye
  @@:

    conout "Compressing MP3 file and placing the result in a WAV container",lf

    mov pCmd, rvcall(cmd_tail)                  ; get original command line
    mov pNxt, rvcall(cmd_tail)                  ; get another copy to modify
    rcall szRep,pNxt,pNxt,"mp3","wav"           ; replace the extension with "wav"

    mov fExt, ptr$(eBuf)
    mcat fExt, "ffmpeg -i ",pCmd," -loglevel 0 -codec:a libmp3lame -q:a 9 -hide_banner @@@@.mp3"
    shell fExt,HIGH_PRIORITY_CLASS

    mov fExt, ptr$(eBuf)
    mcat fExt, "ffmpeg -y -i @@@@.mp3 -c copy -f wav -hide_banner ",pNxt
    shell fExt,HIGH_PRIORITY_CLASS

    rcall DeleteFile,"@@@@.mp3"

    exec "cmd /c cls"
    mfree pCmd
    mfree pNxt
    mov pCmd, rvcall(cmd_tail)                  ; get test copy of command line
    rcall szRemove,pCmd,pCmd,chr$(34)           ; remove the quotes
    mov r11, len(pCmd)
    sub r11, 3
    mov pCmd, left$(pCmd,r11)

    mov fExt, ptr$(eBuf)
    mcat fExt,"cmd /c dir ",chr$(34),pCmd,"*",chr$(34)
    exec fExt

  bye:
    mfree pCmd
    waitkey
    .exit

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end