Jump to content

Bass - How to save file after vst effect ?


Recommended Posts

Hello, I search to save Bass output channel after a VST effect pluggin !!

I found, with an example, how to launch and play Bass VST pluggin. :thumbsup:

But i don't found how to save the result to a file (wav or mp3). >_<

Can anybody help me, please ? :shifty:

#include <BassVST.au3>
#include <BassVSTConstants.au3>
#include <Bass.au3>
#include <BassConstants.au3>

$vst_dll = @ScriptDir & "\epicVerb.dll"
_BASS_STARTUP ( @ScriptDir & "\BASS.dll")
_BASS_VST_STARTUP ( @ScriptDir & "\bass_vst.dll")
$GUI = GuiCreate ("GUI", 990, 190)
_BASS_Init(0, -1, 44100, 0, "") ;Initalize bass.
If @error Then
    MsgBox(0, "Error", "Could not initialize audio")
    Exit
EndIf
$file = FileOpenDialog("Open...", "", "MP3 Files (*.mp3)") ;Open file dialog.
$MusicHandle = _BASS_StreamCreateFile(False, $file, 0, 0, 0) ;Create a stream with file.
If @error Then
    MsgBox(0, "Error", "Could not load audio file" & @CR & "Error = " & @error)
    Exit
EndIf

$chan = _BASS_VST_ChannelSetDSP($MusicHandle, $vst_dll, 0, 0)
_BASS_ChannelPlay($MusicHandle, False) ;Iniate playback
$song_length = _BASS_ChannelGetLength($MusicHandle, $BASS_POS_BYTE) ;Get the length of the song in bytes.
_BASS_VST_EmbedEditor($chan, $GUI)

GUISetState (@SW_SHOW)
While 1
    Sleep(20)
    If GUIGetMsg () = -3 Then
        _BASS_ChannelStop($MusicHandle)
        Exit
    Endif
    If _BASS_ChannelGetPosition($MusicHandle, $BASS_POS_BYTE) >= $song_length Then ExitLoop
WEnd

Func OnAutoItExit()
    _BASS_Free()
EndFunc

Free VST pluggins link :http://audio.tutsplus.com/articles/general/over-90-free-vst-effects-plugins/

Edited by TheDaverMan
Link to comment
Share on other sites

-Should I use Bass_Record ??

-And then how to save the file ? Which Bass function use to save ?

In other language (VB.Net), I saw the use of "WaveWriter" to save !

Can you help me to take the good way ?

Edit

I have found this: Topic: Saving a mixer stream (with syncs) to file

WaveWriter ww = new WaveWriter(filename, mixerStream, 32, true);
         float[] data = new float[32768];
         while (Bass.BASS_ChannelIsActive(mixerStream) == BASSActive.BASS_ACTIVE_PLAYING)
         {
             int length = Bass.BASS_ChannelGetData(mixerStream, data, data.Length);
             if (length > 0 )
                 ww.Write(data, length);
             else break;
         }
        
         ww.Close();

on http://www.un4seen.com/

Edited by TheDaverMan
Link to comment
Share on other sites

Thank you for your response Decipher.

Yes I have read this post.

The simply way to record: " SoundRecorder.exe", but in my case he is not working correctly with my sound card. >_<

Problem: "Periphérique d'enregistrement audio introuvable", he not found record device.

All program sound working correctly but microsoft recorder software not working. :nuke:

Another, working, way (for mee) is to use "ffmpeg", but I found this way not a real solution,

too heavy: 22MB just to save a .wav sound. :

I think the correct solution is to write a function same as "WaveWriter" to record sound to file. But I don't have the level for this.

I think we need to use Bass_ChannelGetData to take data before save it.

I continue to search :sweating: , thx.

Edited by TheDaverMan
Link to comment
Share on other sites

  • 3 weeks later...

I have found a solution to record sound after VST effect. :sorcerer:

I post the resulting code:

#include <BASS.au3>
#include <BASSConstants.au3>
#include <BASSVST.au3>
#include <BASSVSTConstants.au3>
#include <BASSENC.au3>
#include <BASSMIX.au3>
#include <File.au3>

Global $VSTdll = @ScriptDir & "\VST\epicVerb.dll"
Global $BassDir = @ScriptDir & "\DLL\"
Global $Buffer = DllStructCreate("byte[20000]")
Global $BufferPointer = DllStructGetPtr($Buffer)
Global $BufferSize = DllStructGetSize($Buffer)

#Region BASS INIT

_BASS_STARTUP($BassDir & "Bass.dll")
___Debug(@error, " _BASS_STARTUP "&@error)

_BASS_VST_STARTUP($BassDir & "bassvst.dll")
___Debug(@error, " _BASS_VST_STARTUP "&@error)

_BASS_Encode_Startup($BassDir & "bassenc.dll")
___Debug(@error, " _BASS_Encode_Startup "&@error)

_BASS_MIX_STARTUP($BassDir & "bassmix.dll")
___Debug(@error, " _BASS_MIX_STARTUP "&@error)

_BASS_Init($BASS_DEVICE_DEFAULT, -1, 44100, 0, "Null")
___Debug(@error, " _BASS_Init "&@error)

#EndRegion BASS INIT
;
$SoundFile = FileOpenDialog("Open...", @UserProfileDir & "\Music", "MP3,Wav Files (*.wav;*.mp3)", 1)


$StreamHandle = _BASS_StreamCreateFile(False, $SoundFile, 0, 0, $BASS_STREAM_DECODE);$BASS_STREAM_DECODE) ; Create a stream1 with file.
___Debug(@error, "_BASS_StreamCreateFile ")


$InfoStream = _BASS_ChannelGetInfo($StreamHandle) ; Get info on stream(freq, chan, ...)
___Debug(@error, "_BASS_ChannelGetInfo ")

$StreamMixerHandle = _BASS_Mixer_StreamCreate($InfoStream[0], $InfoStream[1], BitOR($BASS_MIXER_END, $BASS_STREAM_DECODE)) ; Create a streamMixer with same freq and num of Chan
___Debug(@error, "_BASS_Mixer_StreamCreate "&@error)


_BASS_Mixer_StreamAddChannel($StreamMixerHandle, $StreamHandle, 0) ; Add stream1 on streamMixer
___Debug(@error, "_BASS_Mixer_StreamAddChannel "&@error)


$VSTchanHandle = _BASS_VST_ChannelSetDSP($StreamHandle, $VSTdll, 1, 1) ; Assigns a VST effects to stream1
___Debug(@error, "_BASS_VST_ChannelSetDSP ")

Sleep(2500) ; Wait 2,5sec, to fill the Mixer buffer before recording

$hEncoder = _BASS_Encode_Start($StreamMixerHandle, @ScriptDir & "\TEST.wav", $BASS_ENCODE_PCM) ; Start encoding from streamMixer
___Debug(@error, "_BASS_Encode_Start ")

$iBytes = _BASS_ChannelGetLength($StreamHandle, $BASS_POS_BYTE) ; Get size in bytes
___Debug(@error, "_BASS_ChannelGetLength " & $iBytes)

$iDone = 0 ; Init length counter

While _BASS_ChannelIsActive($StreamMixerHandle) ; while streamMixer actif
     $iLength = _BASS_ChannelGetData($StreamMixerHandle, $BufferPointer, $BufferSize) ; Read data
     ___Debug(@error, "_BASS_ChannelGetData " & $iLength & " bytes ")

     $iDone += $iLength ; Increment lenghtCounter with data
     ___Debug(-1, Round($iDone * 100 / $iBytes) & "% done") ; Check counter Error
WEnd

_BASS_Encode_Stop($hEncoder) ; Stop encoding
___Debug(@error, "_BASS_Encode_Stop ")

_BASS_StreamFree($StreamMixerHandle) ; Release streamMixer
___Debug(@error, "_BASS_StreamFree ")


Func ___DeBug($Error, $sAction)
    Switch $Error
        Case -1
            ConsoleWrite(@CRLF & "-" & $sAction & @CRLF)
        Case 0
            ConsoleWrite(@CRLF & "+" & $sAction & " - OK" & @CRLF)
        Case Else
            ConsoleWrite(@CRLF & "!" & $sAction & " - FAILED" & @CRLF)
            Exit
    EndSwitch
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...