Platforms to show: All Mac Windows Linux Cross-Platform

/Tools/SoundFile/SoundFile convert


Required plugins for this example: MBS Tools Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Tools/SoundFile/SoundFile convert

This example is the version from Fri, 17th Feb 2022.

Project "SoundFile convert.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
EventHandler Sub Open() Dim f As FolderItem = GetFolderItem("libsndfile.dylib") if SoundFileMBS.LoadLibrary(f) then MsgBox "Library loaded"+EndOfLine+EndOfLine+SoundFileMBS.Version else MsgBox "Failed to load library."+EndOfLine+EndOfLine+SoundFileMBS.LoadErrorMessage quit end if Dim inputFile As FolderItem = SpecialFolder.Desktop.Child("test.wav") Dim inputSound As SoundFileMBS = SoundFileMBS.Open(inputFile) If inputSound = Nil Then MsgBox "Failed to open sound." Return End If Dim inputInfo As SoundFileInfoMBS = inputSound.Info MsgBox Str(inputInfo.Frames)+" frames, "+Str(inputInfo.SampleRate)+" Hz." #If False Then // just copy to new file Dim outputInfo As SoundFileInfoMBS = inputInfo Dim outputFile As FolderItem = SpecialFolder.Desktop.Child("output.wav") #Else // or convert to new file format Dim outputInfo As New SoundFileInfoMBS outputInfo.Channels = inputInfo.Channels outputInfo.Format = inputInfo.kFormatAU + inputInfo.kFormatPCM16 // <-- we change to something else outputInfo.Frames = inputInfo.Frames outputInfo.SampleRate = inputInfo.SampleRate outputInfo.Sections = inputInfo.Sections outputInfo.Seekable = inputInfo.Seekable Dim isValid As Boolean = inputInfo.IsValid Dim outputFile As FolderItem = SpecialFolder.Desktop.Child("output.au") #EndIf Dim outputSound As SoundFileMBS = SoundFileMBS.Create(outputFile, outputInfo) If outputSound = Nil Then MsgBox "Failed to create sound." Return End If Dim BufferSampleSize As Integer = 10000 System.DebugLog "BufferSampleSize: "+Str(BufferSampleSize) Dim data As New MemoryBlock(4 * BufferSampleSize*2) // 4 = size of float in bytes Dim p As ptr = data System.DebugLog "data: "+Str(p) Dim written As Integer Dim count As Integer = inputSound.ReadSingleFrames(p, BufferSampleSize) System.DebugLog "count: "+Str(count) While count > 0 written = outputSound.WriteSingle(p, count*2) System.DebugLog "written: "+Str(written) count = inputSound.ReadSingleFrames(p, BufferSampleSize) System.DebugLog "count: "+Str(count) Wend System.DebugLog "done" outputSound.Close inputSound.close End EventHandler
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project

See also:

The items on this page are in the following plugins: MBS Tools Plugin.


The biggest plugin in space...