Load WAV file as TAudioSample (oggsaver.mod)?

BlitzMax Forums/BlitzMax Programming/Load WAV file as TAudioSample (oggsaver.mod)?

Grisu(Posted 2015) [#1]
Hi guys,


I'm trying to load an existing WAV file and output it as an OGG file via the axe.mod.oggsaver (http://max-edit.googlecode.com/svn/trunk/mod/axe.mod/oggsaver.mod/).

I can't figure out how to turn the Wav file data / header into a TAudioSample object so I can load and then covert the file later.

Has anyone tried such stuff yet?

Thanks
Grisu


BlitzSupport(Posted 2015) [#2]
Either I'm missing something or you're going to kick yourself...

Local test:TAudioSample = LoadAudioSample ("my.wav")

If test

	sound:TSound = LoadSound (test)
	
	PlaySound sound
	Delay 1000
	
EndIf



Grisu(Posted 2015) [#3]
Thanks Skid!

Looks like my framework is missing something. Or it doesn't like the MaxGui driver (hopefully Seb isn't listening). :(

Example code
SuperStrict

Framework Maxgui.Drivers ' <<<<< exclude the maxgui driver line and it works at it should?!
Import BRL.Blitz
Import BRL.Filesystem
Import BRL.GLGraphics
Import BRL.GLMax2D
Import BRL.Audio
Import BRL.AudioSample
Import BRL.Max2D
Import Axe.Oggsaver

Graphics 200,120

Global hwnd:Int = GetBlitzmaxWindow()
Assert hwnd Else "Could not find blitzmax window"

Global OldWindowFunc:Int = SetWindowFunc( hwnd, DropWindowFunc)
DragAcceptFiles( hwnd, True)

Repeat

	Flip
	Cls
		
Until KeyHit(KEY_ESCAPE) Or AppTerminate()
End


Const WM_DROPFILES:Int = 563

Function DropWindowFunc:Int( hwnd:Int, msg:Int, wparam:Int, lparam:Int) "Win32"
	Local hdr:Int Ptr = Int Ptr(lparam)
	Select msg
		Case WM_DROPFILES
			Local count:Int = DragQueryFile( wparam, -1, Null, 0)
			Local files:String[count]			
			For Local i:Int = 0 Until count
				Local sz:Int = DragQueryFile( wparam, i, Null, 0)
				Local buf:Byte[sz+1]
				DragQueryFile( wparam, i, buf, buf.Length)
				files[i] = String.FromBytes( buf, sz)
				
				Print ""
				Print "Dropped Wav-File: "+files[i]
				Print "Loading Wav-File... "+files[i]
				Local test:TAudioSample=LoadAudioSample(files[i])
				If test

				Print "Ogging now... "
  				'SaveOGG(sample:TAudioSample,URL:Object,compression#=0.1)
				SaveOGG(test,"_temp_"+i+".ogg",0.1)
				Print ""

'				Local sound:TSound = LoadSound (test)
'				PlaySound sound
'				Delay 1000
'               End

	            Else 
	               Print "Error! Wav-File not loaded!"
				EndIf 
			Next
			Print "Exiting app!"
			End ' Done converting


		' this MUST be handled, otherwise MaxGUI freezes on window close.
		Case WM_DESTROY
			SetWindowLong( hwnd, GWL_WNDPROC, OldWindowFunc)
			
	EndSelect
	Return CallWindowProc( OldWindowFunc, hwnd, msg, wparam, Int(lparam))
EndFunction

Const GWL_WNDPROC:Int = -4

Extern "Win32"	
	Function SetWindowLong:Int(HWND:Int,nIndex:Int,dwNewLong:Int) = "SetWindowLongA@12"
	Function GetWindowLong:Int(HWND:Int,nIndex:Int) = "GetWindowLongA@8"	
	Function CallWindowProc:Int( prevwndproc:Int, hwnd:Int, msg:Int, wparam:Int, lparam:Int) = "CallWindowProcA@20"
	Function DragAcceptFiles:Int( hwnd:Int, enable:Int)
	Function DragQueryFile:Int( hdrop:Int, index:Int, buf:Byte Ptr, sz:Int)
EndExtern

Function SetWindowFunc:Int( hwnd:Int, newfunc:Int( hwnd:Int, msg:Int, wparam:Int, lparam:Int))
	Local oldfunc:Int = GetWindowLong( hwnd, GWL_WNDPROC)
	SetWindowLong( hwnd, GWL_WNDPROC, Int(Byte Ptr newfunc))
	Return oldfunc
EndFunction

Function GetBlitzmaxWindow:Int()
?Win32
	Extern "Win32"
		Function FindWindowA:Int( classname$z, windowtitle$z)	
	EndExtern
	Local handle:Int
	handle = FindWindowA( "BBDX9Device Window Class", AppTitle)									' D3D9Max2D
	If Not handle Then handle = FindWindowA( "BlitzMax GLGraphics", AppTitle)			' GLMax2D
	If Not handle Then handle = FindWindowA( "BBDX7Device Window Class", AppTitle)	' D3D7Max2D
	If Not handle Then handle  = FindWindowA( "BLITZMAX_WINDOW_CLASS", AppTitle)		' MaxGUI
	Return handle
?
EndFunction


Drag & Drop a Wav file onto the bmx window and it will convert the file(s) as needed. But only if you exclude the framework MaxGui driver at the very top.

My guess is that the framework needs more modules. Any ideas?


Henri(Posted 2015) [#4]
Hi Grisu,

you probably need brl.wavloader.

-Henri


BlitzSupport(Posted 2015) [#5]
Try just importing Maxgui.Drivers and Axe.Oggsaver, commenting out all of your BRL.xxx imports to start with.

Top Tip: Use Jim Brown's awesome Framework Assistant to figure out what to import just prior to release. No need to do this while developing, IM-most-HO...

I'm not skid, BTW, Grisu -- think you'll find that's skidracer! :P


Grisu(Posted 2015) [#6]
Ups! Sorry James, somehow after hours of coding, Skid was on my mind. :(

Henri was right as as usual. Also I learned that "utf8::" doesn't work with LoadAudioSample() or SaveOGG() and I managed to update the ogg module to the latest lib files.

Is there a way to get some kind of progress indicator (0...100%) while encoding? The ogg process "hangs" my app for too long as users have to be able to encode 1 GB+ WAV files. Another possible solution could be to create an extra "encoding thread".


Henri(Posted 2015) [#7]
That definately sounds like a job for threading.

-Henri