IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

WinDev Discussion :

Encapsulation de l'API BASS.dll (audio)


Sujet :

WinDev

  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    486
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 486
    Points : 875
    Points
    875
    Par défaut Encapsulation de l'API BASS.dll (audio)
    Comme promis, voici l'encapsulation des fonctions de base des API de la bibliothèque audio Bass.dll

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    CONSTANT
        BassDLL             = "Bass"
        BassFX              = "Bass_FX"
     
        MAX_PATH            = 260
     
        BASS_DEVICE_MONO    = 2
        BASS_DEVICE_LATENCY = 256
        BASS_DEVICE_CPSPEAKERS = 1024
        BASS_DEVICE_SPEAKERS   = 2048
        BASS_DEVICE_NOSPEAKER  = 4096
     
        BASS_ACTIVE_STOPPED = 0
        BASS_ACTIVE_PLAYING = 1
        BASS_ACTIVE_STALLED = 2
        BASS_ACTIVE_PAUSED  = 3
     
        BASS_SYNC_END       = 2
        BASS_SYNC_SETPOS    = 11
        BASS_SYNC_ONETIME   = 0x80000000
        BASS_SYNC_MIXTIME   = 0x40000000
        BASS_POS_BYTE       = 0
        BASS_SYNC_POS       = 0
     
        BASS_ATTRIB_FREQ    = 1
        BASS_ATTRIB_VOL     = 2
        BASS_ATTRIB_PAN     = 3
     
        BASS_SAMPLE_LOOP    = 4
        BASS_SAMPLE_FLOAT   = 256
        BASS_SAMPLE_8BITS   = 1
        BASS_SAMPLE_MONO    = BASS_DEVICE_MONO
     
        BASS_CONFIG_MP4_VIDEO   = 0x10700       // Play the audio from MP4 videos
        BASS_TAG_MP4            = 7             // MP4/iTunes metadata
        BASS_AAC_DOWNMATRIX     = 0x400000      // downmatrix TO stereo
        BASS_CTYPE_STREAM_AAC   = 0x10B00       // BASS_CHANNELINFO type
        BASS_CTYPE_STREAM_MP4   = 0x10B01       // BASS_CHANNELINFO type
        BASS_STREAM_DECODE      = 0x200000      // Don't play the stream, only decode (BASS_ChannelGetData)
        BASS_STREAM_PRESCAN     = 0x20000       //
        BASS_STREAM_AUTOFREE    = 262144        // automatically free the stream when it stop/ends
     
        WAVE_FORMAT_4S16        = 0x00000800    // 44.1   kHz, Stereo, 16-bit
        BassDuration            = 0.000566893424    // 0.0005659 Accuracy is 1/100 of second
     
        BASS_ATTRIB_TEMPO       = 0x10000
        BASS_ATTRIB_TEMPO_PITCH = 0x10001
        BASS_ATTRIB_TEMPO_FREQ  = 0x10002
     
        BASS_DEVICE_ENABLED     = 1
        BASS_DEVICE_DEFAULT     = 2
        BASS_DEVICE_INIT        = 4
     
        BASS_FX_FREESOURCE      = 0x10000
        BASS_CONFIG_BUFFER      = 0
        BASS_CONFIG_GVOL_STREAM = 5
     
        BASS_CONFIG_UPDATEPERIOD  = 1
     
    END
     
    BASS_CHANNELINFO is structure
        freq        is int  // default playback rate
        chans       is int  // channels
        flags       is int  // BASS_SAMPLE/STREAM/MUSIC/SPEAKER flags
        ctype       is int  // type of channel
        origres     is int  // original resolution
        plugin      is int  // plugin
        sample      is int  // sample
        filename    is int  // AS ASCIIZ PTR   ' const char * // filename
    END
     
    BASS_INFO is structure
        flags is int         // device capabilities (DSCAPS_xxx flags)
        hwsize is int        // size of total device hardware memory
        hwfree is int        // size of free device hardware memory
        freesam is int       // number of free sample slots in the hardware
        free3d is int        // number of free 3D sample slots in the hardware
        minrate is int       // min sample rate supported by the hardware
        maxrate is int       // max sample rate supported by the hardware
        eax is int           // device supports EAX? (always BASSFALSE if BASS_DEVICE_3D was not used)
        minbuf is int        // recommended minimum buffer length in ms (requires BASS_DEVICE_LATENCY)
        dsver is int         // DirectSound version
        latency is int       // delay (in ms) before start of playback (requires BASS_DEVICE_LATENCY)
        initflags is int     // BASS_Init "flags" parameter
        speakers is int      // number of speakers available
        freq is int          // current output ra
    END
     
    BASS_DEVICEINFO is structure
        pName is 4-byte unsigned int
        pDriver is 4-byte unsigned int
        nFlags is int
    END
     
    /////////////////////////////////////////////////////////////////////////////////////////////////////
    FUNCTION AdjustSize(LOCAL nChannel is int)
    nRet is int = 1
    IF (nChannel) THEN
        bbInfo is BASS_CHANNELINFO
        BASS_ChannelGetInfo(nChannel, bbInfo)
        IF (bbInfo.chans = 1) THEN nRet = 2
    END
    RESULT nRet
     
    FUNCTION BASS_ChannelGetAttribute(LOCAL nChannel is int, LOCAL nAttrib is int, rLevel is 4-byte real)
    nRet is int = API(BassDLL, "BASS_ChannelGetAttribute", nChannel, nAttrib, &rLevel)
    RESULT nRet
     
    FUNCTION BASS_ChannelGetData(LOCAL nChan is int, LOCAL nPtrBuffer is int, LOCAL nLength is int)
    nRet is int = API(BassDLL, "BASS_ChannelGetData", nChan, nptrBuffer, nLength)
    RESULT nRet
     
    FUNCTION BASS_ChannelGetInfo(LOCAL nChan is int, stInfo is BASS_CHANNELINFO)
    nRet is int = API(BassDLL, "BASS_ChannelGetInfo", nChan, &stInfo)
    RESULT nRet
     
    FUNCTION BASS_ChannelGetLength(LOCAL nChannel is int, LOCAL nMode is int)
    nRet is int = API(BassDLL, "BASS_ChannelGetLength", nChannel, nMode)
    nRet = nRet * AdjustSize(nChannel)
    RESULT nRet
     
    FUNCTION BASS_ChannelGetLevel(LOCAL nChannel is int)
    nRet is int = API(BassDLL, "BASS_ChannelGetLevel", nChannel)
    RESULT nRet
     
    FUNCTION BASS_ChannelGetPosition(LOCAL nChannel is int, LOCAL nFlag is int)
    nPos is 8-byte int = API(BassDLL, "BASS_ChannelGetPosition", nChannel, nFlag)
    IF nPos = -1 THEN
        nPos = 0
    END
    nPos = nPos * AdjustSize(nChannel)
    RESULT nPos
     
    FUNCTION BASS_ChannelIsActive(LOCAL nChannel is int)
    nRet is int = API(BassDLL, "BASS_ChannelIsActive", nChannel)
    RESULT nRet
     
    FUNCTION BASS_ChannelPause(LOCAL nChannel is int)
    nRet is int = API(BassDLL, "BASS_ChannelPause", nChannel)
    RESULT nRet
     
    FUNCTION BASS_ChannelPlay(LOCAL nChannel is int, LOCAL nMode is int)
    nRet is int = API(BassDLL, "BASS_ChannelPlay", nChannel, nMode)
    RESULT nRet
     
    PROCEDURE BASS_ChannelRemoveSync(LOCAL nChannel is int, LOCAL nSync is int)
    IF nSync THEN API(BassDLL, "BASS_ChannelRemoveSync", nChannel, nSync)
     
    FUNCTION BASS_ChannelSetAttribute(LOCAL nChannel is int, LOCAL nAttrib is int, LOCAL rLevel is 4-byte real)
    nRet is int = API(BassDLL, "BASS_ChannelSetAttribute", nChannel, nAttrib, rLevel)
    RESULT nRet
     
    FUNCTION BASS_ChannelSetPosition(LOCAL nChannel is int, LOCAL nPosLow is int, LOCAL nMode is int)
    nPosLow = nPosLow / AdjustSize(nChannel)
    nRet is int = API(BassDLL, "BASS_ChannelSetPosition", nChannel, nPosLow, 0, nMode)
    RESULT nRet
     
    FUNCTION BASS_ChannelStop(LOCAL nChannel is int)
    nRet is int = API(BassDLL, "BASS_ChannelStop", nChannel)
    RESULT nRet
     
    PROCEDURE BASS_ChannelUpdate(LOCAL nChannel is int, LOCAL nValue is int)
    nRet is int = API(BassDLL, "BASS_ChannelUpdate", nChannel, nValue)
    RESULT nRet
     
    FUNCTION BASS_Free()
    nRet is int = API(BassDLL, "BASS_Free")
    RESULT nRet
     
    FUNCTION BASS_FX_TempoCreate(LOCAL nChan is int, LOCAL nFlag is int)
    nRet is int = API(BassFX, "BASS_FX_TempoCreate", nChan, nFlag)
    //if nRet = 0 THEN trace(BASS_ErrorGetCode())
    RESULT nRet
     
    PROCEDURE BASS_GetDevice()
    nRet is int =  API(BassDLL, "BASS_GetDevice")
    RESULT nRet
     
    FUNCTION BASS_GetDeviceInfo(LOCAL nDevice is int, DeviceInfo is BASS_DEVICEINFO )
    nRet is int = API(BassDLL, "BASS_GetDeviceInfo", nDevice, &DeviceInfo)
    RESULT nRet
     
    FUNCTION BASS_GetInfo(stInfo is BASS_INFO)
    nRet is int = API(BassDLL, "BASS_GetInfo", &stInfo)
    RESULT nRet
     
    FUNCTION BASS_GetVolume()
    rVolume is 4-byte real = API(BassDLL, "BASS_GetVolume")
    RESULT rVolume
     
    FUNCTION BASS_Init(LOCAL nDevice is int, LOCAL nSampleRate is int, LOCAL nFlags is int, LOCAL nWindow is int, LOCAL nclsid is int = 0)
    nRet is int = API(BassDLL, "BASS_Init", nDevice, nSampleRate, nFlags, nWindow, nclsid)
    RESULT nRet
     
    FUNCTION BASS_SetConfig(LOCAL nOption is int, LOCAL nValue is int)
    nRet is int = API(BassDLL, "BASS_SetConfig", nOption, nValue)
    RESULT nRet
     
    FUNCTION BASS_SetDevice(LOCAL nDevice is int)
    nRet is int = API(BassDLL, "BASS_SetDevice", nDevice)
    RESULT nRet
     
    FUNCTION BASS_SetVolume(LOCAL rVolume is 4-byte real)
    nRet is int = API(BassDLL, "BASS_SetVolume", rVolume)
    RESULT nRet
     
    PROCEDURE BASS_SPEAKER_N(LOCAL n is int)
    nRet is int = n * 16777216
    RESULT nRet
     
    FUNCTION BASS_StreamCreateFile(LOCAL bMem is boolean, LOCAL sFile is string ASCIIZ on MAX_PATH, LOCAL nOffset is unsigned int, LOCAL nLength is unsigned int, LOCAL nFlags is unsigned int)
    nRet is int = API(BassDLL, "BASS_StreamCreateFile", bMem, sFile, nOffset, 0, nLength, 0, nFlags)
    RESULT nRet
     
    FUNCTION BASS_StreamCreateMemory(LOCAL bMem is boolean, LOCAL lpMem is system int, LOCAL nOffset is unsigned int, LOCAL nLength is unsigned int, LOCAL nFlags is unsigned int)
    nRet is int = API(BassDLL, "BASS_StreamCreateFile", bMem, lpMem, nOffset, 0, nLength, 0, nFlags)
    RESULT nRet
     
    FUNCTION BASS_StreamCreateURL(LOCAL sFile is string ASCIIZ on MAX_PATH, LOCAL nOffset is unsigned int, LOCAL nFlags is unsigned int, LOCAL nptrDOWNLOADPROC is unsigned int, LOCAL nUser is unsigned int)
    nRet is int = API(BassDLL, "BASS_StreamCreateURL", sFile, nOffset, nFlags, nptrDOWNLOADPROC, nUser)
    RESULT nRet
     
    FUNCTION BASS_StreamFree(LOCAL nChannel is int)
    nRet is int = API(BassDLL, "BASS_StreamFree", nChannel)
    RESULT nRet
    Le ZIP du fichier .WDG est attaché à ce message.

    ...
    Fichiers attachés Fichiers attachés

  2. #2
    Membre éprouvé Avatar de WDKyle
    Homme Profil pro
    Analyste-Programmeur
    Inscrit en
    Septembre 2008
    Messages
    1 200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Analyste-Programmeur

    Informations forums :
    Inscription : Septembre 2008
    Messages : 1 200
    Points : 962
    Points
    962
    Par défaut
    Bonsoir,

    Je cherche à régler le volume lors d'un enregistrement mais en vain...

    J'ai essayé avec la fonction BASS_RecordSetInput :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    SI BASS_RecordSetInput(0, BASS_INPUT_ON, (POT_Volume / POT_Volume..BorneMax)) = Faux ALORS
    	Erreur(BASS_ErrorGetCode())
    FIN
    J'ai le code d'erreur -1 qui correspond à BASS_ERROR_UNKNOWN Some other mystery problem!

    Est-ce la bonne fonction pour régler le volume d'enregistrement ?

    Merci

  3. #3
    Membre actif
    Inscrit en
    Octobre 2013
    Messages
    274
    Détails du profil
    Informations forums :
    Inscription : Octobre 2013
    Messages : 274
    Points : 248
    Points
    248
    Par défaut
    bonjour Patrice

    merci pour la contribution qui m'aurait bien servie il y a quelques années. Ceci dit cela m'a permis à l'époque d'apprendre pas mal de chose.

    Le seul truc que je n'avais pas réussi à faire et qu'il me manque toujours.
    C'est de pouvoir enregistrer le flux radio écouté? Tes sources le font elles?

  4. #4
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    486
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 486
    Points : 875
    Points
    875
    Par défaut
    Oui, c'est possible avec BASS.DLL, il faut utiliser les API BASS_Encode_Start et BASS_ChannelGetData, on peut même utiliser LAME ou OGGENC pour créer un mp3 ou un OGG à la volée.

    Sinon il faut utiliser une carte audio-multiplex et capturer le son directement au format PCM, avec l'API MMIO bas niveau.

    ...

  5. #5
    Membre éprouvé Avatar de WDKyle
    Homme Profil pro
    Analyste-Programmeur
    Inscrit en
    Septembre 2008
    Messages
    1 200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Analyste-Programmeur

    Informations forums :
    Inscription : Septembre 2008
    Messages : 1 200
    Points : 962
    Points
    962
    Par défaut
    Citation Envoyé par Patrice Terrier Voir le message
    Oui, c'est possible avec BASS.DLL, il faut utiliser les API BASS_Encode_Start et BASS_ChannelGetData, on peut même utiliser LAME ou OGGENC pour créer un mp3 ou un OGG à la volée.

    Sinon il faut utiliser une carte audio-multiplex et capturer le son directement au format PCM, avec l'API MMIO bas niveau.

    ...
    Ce n'était pas pour ma question cette réponse ?

  6. #6
    Expert éminent
    Avatar de jurassic pork
    Homme Profil pro
    Bidouilleur
    Inscrit en
    Décembre 2008
    Messages
    3 951
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Bidouilleur
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2008
    Messages : 3 951
    Points : 9 280
    Points
    9 280
    Par défaut
    hello WDKyle,

    WDKyle a gribouillé :
    J'ai essayé avec la fonction BASS_RecordSetInput :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    SI BASS_RecordSetInput(0, BASS_INPUT_ON, (POT_Volume / POT_Volume..BorneMax)) = Faux ALORS
    	Erreur(BASS_ErrorGetCode())
    FIN
    J'ai le code d'erreur -1 qui correspond à BASS_ERROR_UNKNOWN Some other mystery problem!
    Comment est défini l'appel à la fonction BASS_RecordSetInput de la dll ?
    Que se passe-t-il si tu fais :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    SI BASS_RecordSetInput(0, BASS_INPUT_ON, 0.5) = Faux ALORS
    	Erreur(BASS_ErrorGetCode())
    Ami calmant, J.P
    Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

  7. #7
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    486
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 486
    Points : 875
    Points
    875
    Par défaut
    Voilà un exemple qui montre la syntaxe à utiliser pour enregistrer directement au format OGG

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    sRecordFile is string = gsActiveSong; sRecordFile = Replace(sRecordFile, " ", "_") + ".ogg"
    gRec.sFileName = gsExport + Right(DateSys, 6) + "_" + sRecordFile
    sCmdLine is string = ExePath() + "OGGENC2.exe -o " + Quote + gRec.sFileName + Quote + " -"
    gRec.channel = BASS_Encode_Start(ZSL_GetBassMixer(), sCmdLine, BASS_ENCODE_AUTOFREE)
    Pour le reste, voir l'exemple livré avec BassEnc, à savoir : rectest.c

    Code C : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    /*
    	BASSenc recording example
    	Copyright (c) 2003-2011 Un4seen Developments Ltd.
    */
     
    #include <windows.h>
    #include <commctrl.h>
    #include <stdio.h>
    #include "bass.h"
    #include "bassenc.h"
     
    HWND win;
     
    #define FREQ 44100
    #define CHANS 2
     
    int input;				// current input source
    int encoder;			// current encoder
     
    WAVEFORMATEX *acmform=0;	// ACM codec format
    DWORD acmformlen;			// ACM codec format size
     
    HRECORD rchan=0;		// recording channel
    HSTREAM chan=0;			// playback channel
    HENCODE hencode;		// encoder handle
     
    // encoder command-lines and output files
    const char *commands[2]={
    	"oggenc -o bass.ogg -", // oggenc (OGG)
    	"lame --alt-preset standard - bass.mp3" // lame (MP3)
    };
    const char *files[3]={"bass.ogg","bass.mp3","bass.wav"}; // OGG,MP3,ACM
     
    // display error messages
    void Error(const char *es)
    {
    	char mes[200];
    	sprintf(mes,"%s\n(error code: %d)",es,BASS_ErrorGetCode());
    	MessageBox(win,mes,0,0);
    }
     
    // messaging macros
    #define MESS(id,m,w,l) SendDlgItemMessage(win,id,m,(WPARAM)(w),(LPARAM)(l))
    #define DLGITEM(id) GetDlgItem(win,id)
     
    BOOL CALLBACK RecordingCallback(HRECORD handle, const void *buffer, DWORD length, void *user)
    {
    	return BASS_Encode_IsActive(handle); // continue recording if encoder is alive
    }
     
    void StartRecording()
    {
    	if (chan) { // free old recording
    		BASS_StreamFree(chan);
    		chan=0;
    		EnableWindow(DLGITEM(11),FALSE);
    		// close output device before recording incase of half-duplex device
    		BASS_Free();
    	}
    	// start recording (paused to add encoder first)
    	rchan=BASS_RecordStart(FREQ,CHANS,BASS_RECORD_PAUSE,&RecordingCallback,0);
    	if (!rchan) {
    		Error("Couldn't start recording");
    		return;
    	}
    	// get selected encoder (0=OGG, 1=MP3, 2=ACM)
    	if (MESS(18,BM_GETCHECK,0,0)) encoder=2;
    	else encoder=MESS(17,BM_GETCHECK,0,0);
    	if (encoder==2) {
    		if (!BASS_Encode_GetACMFormat(rchan,acmform,acmformlen,(char*)NULL,BASS_ACM_DEFAULT) // select the ACM codec
    			|| !(hencode=BASS_Encode_StartACMFile(rchan,acmform,0,files[2]))) { // start the ACM encoder
    			Error("Couldn't start encoding");
    			BASS_ChannelStop(rchan);
    			rchan=0;
    			return;
    		}
    	} else if (!(hencode=BASS_Encode_Start(rchan,commands[encoder],0,NULL,0))) { // start the OGG/MP3 encoder
    		Error("Couldn't start encoding...\n"
    			"Make sure OGGENC.EXE (if encoding to OGG) is in the same\n"
    			"direcory as this example, or LAME.EXE (if encoding to MP3).");
    		BASS_ChannelStop(rchan);
    		rchan=0;
    		return;
    	}
     
    	BASS_ChannelPlay(rchan,FALSE); // resume recoding
    	MESS(10,WM_SETTEXT,0,"Stop");
    	EnableWindow(DLGITEM(16),FALSE);
    	EnableWindow(DLGITEM(17),FALSE);
    	EnableWindow(DLGITEM(18),FALSE);
    }
     
    void StopRecording()
    {
    	// stop recording & encoding
    	BASS_ChannelStop(rchan);
    	rchan=0;
    	BASS_Encode_Stop(hencode);
    	MESS(10,WM_SETTEXT,0,"Record");
    	EnableWindow(DLGITEM(16),TRUE);
    	EnableWindow(DLGITEM(17),TRUE);
    	EnableWindow(DLGITEM(18),TRUE);
    	// setup output device (using default device)
    	if (!BASS_Init(-1,44100,0,win,NULL)) {
    		Error("Can't initialize output device");
    		return;
    	}
    	// create a stream from the recording
    	if (chan=BASS_StreamCreateFile(FALSE,files[encoder],0,0,0))
    		EnableWindow(DLGITEM(11),TRUE); // enable "play" button
    	else 
    		BASS_Free();
    }
     
    void UpdateInputInfo()
    {
    	char *type;
    	float level;
    	int it=BASS_RecordGetInput(input,&level); // get info on the input
    	MESS(14,TBM_SETPOS,TRUE,level*100); // set the level slider
    	switch (it&BASS_INPUT_TYPE_MASK) {
    		case BASS_INPUT_TYPE_DIGITAL:
    			type="digital";
    			break;
    		case BASS_INPUT_TYPE_LINE:
    			type="line-in";
    			break;
    		case BASS_INPUT_TYPE_MIC:
    			type="microphone";
    			break;
    		case BASS_INPUT_TYPE_SYNTH:
    			type="midi synth";
    			break;
    		case BASS_INPUT_TYPE_CD:
    			type="analog cd";
    			break;
    		case BASS_INPUT_TYPE_PHONE:
    			type="telephone";
    			break;
    		case BASS_INPUT_TYPE_SPEAKER:
    			type="pc speaker";
    			break;
    		case BASS_INPUT_TYPE_WAVE:
    			type="wave/pcm";
    			break;
    		case BASS_INPUT_TYPE_AUX:
    			type="aux";
    			break;
    		case BASS_INPUT_TYPE_ANALOG:
    			type="analog";
    			break;
    		default:
    			type="undefined";
    	}
    	MESS(15,WM_SETTEXT,0,type); // display the type
    }
     
    BOOL InitDevice(int device)
    {
    	BASS_RecordFree(); // free current device (and recording channel) if there is one
    	// initalize new device
    	if (!BASS_RecordInit(device)) {
    		Error("Can't initialize recording device");
    		return FALSE;
    	}
    	{ // get list of inputs
    		int c;
    		const char *i;
    		MESS(13,CB_RESETCONTENT,0,0);
    		for (c=0;i=BASS_RecordGetInputName(c);c++) {
    			MESS(13,CB_ADDSTRING,0,i);
    			if (!(BASS_RecordGetInput(c,NULL)&BASS_INPUT_OFF)) { // this one is currently "on"
    				input=c;
    				MESS(13,CB_SETCURSEL,input,0);
    				UpdateInputInfo();
    			}
    		}
    	}
    	return TRUE;
    }
     
    BOOL CALLBACK dialogproc(HWND h,UINT m,WPARAM w,LPARAM l)
    {
    	switch (m) {
    		case WM_TIMER:
    			{ // update the recording/playback counter
    				char text[30]="";
    				if (rchan) // recording/encoding
    					sprintf(text,"%I64d",BASS_Encode_GetCount(hencode,BASS_ENCODE_COUNT_IN));
    				else if (chan) {
    					if (BASS_ChannelIsActive(chan)) // playing
    						sprintf(text,"%I64d / %I64d",BASS_ChannelGetPosition(chan,BASS_POS_BYTE),BASS_ChannelGetLength(chan,BASS_POS_BYTE));
    					else
    						sprintf(text,"%I64d",BASS_ChannelGetLength(chan,BASS_POS_BYTE));
    				}
    				MESS(20,WM_SETTEXT,0,text);
    			}
    			break;
     
    		case WM_COMMAND:
    			switch (LOWORD(w)) {
    				case IDCANCEL:
    					DestroyWindow(h);
    					break;
    				case 10:
    					if (!rchan)
    						StartRecording();
    					else
    						StopRecording();
    					break;
    				case 11:
    					BASS_ChannelPlay(chan,TRUE); // play the recorded data
    					break;
    				case 13:
    					if (HIWORD(w)==CBN_SELCHANGE) { // input selection changed
    						int i;
    						input=MESS(13,CB_GETCURSEL,0,0); // get the selection
    						// enable the selected input
    						for (i=0;BASS_RecordSetInput(i,BASS_INPUT_OFF,-1);i++) ; // 1st disable all inputs, then...
    						BASS_RecordSetInput(input,BASS_INPUT_ON,-1); // enable the selected
    						UpdateInputInfo(); // update info
    					}
    					break;
    				case 19:
    					if (HIWORD(w)==CBN_SELCHANGE) { // device selection changed
    						int i=MESS(19,CB_GETCURSEL,0,0); // get the selection
    						// initialize the selected device
    						if (InitDevice(i)) {
    							if (rchan) { // continue recording on the new device...
    								HRECORD newrchan=BASS_RecordStart(FREQ,CHANS,0,RecordingCallback,0);
    								if (!newrchan)
    									Error("Couldn't start recording");
    								else {
    									rchan=newrchan;
    									BASS_Encode_SetChannel(hencode,rchan); // move the encoder to the new recording
    								}
    							}
    						}
    					}
    					break;
    			}
    			break;
     
    		case WM_HSCROLL:
    			if (l) { // set input source level
    				float level=SendMessage((HWND)l,TBM_GETPOS,0,0)/100.f;
    				if (!BASS_RecordSetInput(input,0,level)) // failed to set input level
    					BASS_RecordSetInput(-1,0,level); // try master level instead
    			}
    			break;
     
    		case WM_INITDIALOG:
    			win=h;
    			MESS(14,TBM_SETRANGE,FALSE,MAKELONG(0,100));
    			MESS(16,BM_SETCHECK,BST_CHECKED,0);
    			{ // get list of recording devices
    				int c,def;
    				BASS_DEVICEINFO di;
    				for (c=0;BASS_RecordGetDeviceInfo(c,&di);c++) {
    					MESS(19,CB_ADDSTRING,0,di.name);
    					if (di.flags&BASS_DEVICE_DEFAULT) { // got the default device
    						MESS(19,CB_SETCURSEL,c,0);
    						def=c;
    					}
    				}
    				InitDevice(def); // initialize default recording device
    			}
    			SetTimer(h,0,200,0); // timer to update the position display
    			// allocate ACM format buffer, using suggested buffer size
    			acmformlen=BASS_Encode_GetACMFormat(0,NULL,0,(char*)NULL,0);
    			acmform=(WAVEFORMATEX*)malloc(acmformlen);
    			memset(acmform,0,acmformlen);
    			return 1;
     
    		case WM_DESTROY:
    			// release all BASS stuff
    			BASS_RecordFree();
    			BASS_Free();
    			free(acmform); // free ACM format buffer
    			break;
    	}
    	return 0;
    }
     
    int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
    {
    	// check the correct BASS was loaded
    	if (HIWORD(BASS_GetVersion())!=BASSVERSION) {
    		MessageBox(0,"An incorrect version of BASS.DLL was loaded",0,MB_ICONERROR);
    		return 0;
    	}
     
    	{ // enable trackbar support (for the level control)
    		INITCOMMONCONTROLSEX cc={sizeof(cc),ICC_BAR_CLASSES};
    		InitCommonControlsEx(&cc);
    	}
     
    	DialogBox(hInstance,(char*)1000,0,&dialogproc);
     
    	return 0;
    }

  8. #8
    Membre éprouvé Avatar de WDKyle
    Homme Profil pro
    Analyste-Programmeur
    Inscrit en
    Septembre 2008
    Messages
    1 200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Analyste-Programmeur

    Informations forums :
    Inscription : Septembre 2008
    Messages : 1 200
    Points : 962
    Points
    962
    Par défaut
    Citation Envoyé par jurassic pork Voir le message
    hello WDKyle,

    WDKyle a gribouillé :


    Comment est défini l'appel à la fonction BASS_RecordSetInput de la dll ?
    Que se passe-t-il si tu fais :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    SI BASS_RecordSetInput(0, BASS_INPUT_ON, 0.5) = Faux ALORS
    	Erreur(BASS_ErrorGetCode())
    Ami calmant, J.P
    Salut jurrasic pork,

    J'avais testé directement comme dans ton code et j'ai toujours un retour d'erreur -1

    Ma description est bonne je pense...

    Param 1: apiEntier_4 param 2: apiEntier_4 et param 3 : apiRéel_4

    Merci de ton aide

  9. #9
    Membre éprouvé Avatar de WDKyle
    Homme Profil pro
    Analyste-Programmeur
    Inscrit en
    Septembre 2008
    Messages
    1 200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Analyste-Programmeur

    Informations forums :
    Inscription : Septembre 2008
    Messages : 1 200
    Points : 962
    Points
    962
    Par défaut
    Bonjour Patrice,

    Je me suis inspiré de votre code pour enregistrer en MP3 avec la fonction BASS_Encode_Start.

    Par contre, j'ai pour handle de retour 0

    Voici ma déclaration de la fonction :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    BASS_Encode_Start est une Description d'API
    BASS_Encode_Start.NomDLL = "bassenc.dll"
    BASS_Encode_Start.NomFonction = "BASS_Encode_Start"
    BASS_Encode_Start.TypeRetour = apiEntier_4
    BASS_Encode_Start.Paramètre[1].Type = apiEntier_4
    BASS_Encode_Start.Paramètre[2].Type = apiEntier_4
    BASS_Encode_Start.Paramètre[3].Type = apiEntier_4
    BASS_Encode_Start.Paramètre[4].Type = apiEntierSystème
    BASS_Encode_Start.Paramètre[5].Type = apiEntierSystème
    Et je l'utilise comme ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    BASS_Encode_Start(Stream_R1, "lame --alt-preset standard - output.mp3", 0, NULL, 0)
    Me suis-je trompé quelque part ?

    Merci par avance.

  10. #10
    Membre éprouvé Avatar de WDKyle
    Homme Profil pro
    Analyste-Programmeur
    Inscrit en
    Septembre 2008
    Messages
    1 200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Analyste-Programmeur

    Informations forums :
    Inscription : Septembre 2008
    Messages : 1 200
    Points : 962
    Points
    962
    Par défaut
    Bonsoir,

    Je reviens sur ce sujet car je cherche le moyen de pouvoir modifier le volume d'entrée ligne d'une carte son. Le volume d'enregistrement pas le volume de lecture.

    Avec Bass, j'ai cru comprendre qu'il fallait utiliser la fonction BASS_RecordSetInput celle-ci fonctionne mais n'a aucun effet...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    BASS_RecordSetInput(0, BASS_INPUT_NONE, 0.5f)
    Je me suis tourné vers la possibilité de modifier le volume d'un stream avec BASS_ChannelSetAttribute mais peine perdu... Cela n'as aucun effet non plus !

    Faut-il que je code cela en bas niveau avec l'api winmm.dll et mixerSetControlDetails ? Car je ne n'en est pas les capacités...

    Merci.

  11. #11
    Expert éminent
    Avatar de jurassic pork
    Homme Profil pro
    Bidouilleur
    Inscrit en
    Décembre 2008
    Messages
    3 951
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Bidouilleur
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2008
    Messages : 3 951
    Points : 9 280
    Points
    9 280
    Par défaut
    hello,
    vérifie la syntaxe et les paramètres de ta fonction par rapport à la version employée, moi dans une doc unseen j'ai vu :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Example
    Enable the first input, and set its volume level to 50%.
    BASS_RecordSetInput(0, BASS_INPUT_ON, 0.5);
    Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

  12. #12
    Membre éprouvé Avatar de WDKyle
    Homme Profil pro
    Analyste-Programmeur
    Inscrit en
    Septembre 2008
    Messages
    1 200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Analyste-Programmeur

    Informations forums :
    Inscription : Septembre 2008
    Messages : 1 200
    Points : 962
    Points
    962
    Par défaut
    @jurassic pork : Cela donne le même résultat... J'ai juste mis le flag BASS_INPUT_NONE car je ne souhaite changer que le volume.

    Je viens de faire différents test et c'est un soucis de carte son...

    La fonction marche très bien avec une carte son basique intégré au PC du genre Realtek, j'ai bien le niveau entrée ligne ou microphone qui est modifié. Par contre, avec une carte son pro cela ne fonctionne pas... Cela modifie le volume en lecture de l'application. Allez comprendre !

    Avant de passer par winmm.dll, aucun moyen de modifier le volume du stream HRECORD ? La fonction BASS_ChannelSetAttribute permet de manipuler un stream HRECORD d'après la doc mais cela n'a aucun effet...

    http://www.un4seen.com/doc/#bass/BAS...Attribute.html

    Merci !

  13. #13
    Expert éminent
    Avatar de jurassic pork
    Homme Profil pro
    Bidouilleur
    Inscrit en
    Décembre 2008
    Messages
    3 951
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Bidouilleur
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2008
    Messages : 3 951
    Points : 9 280
    Points
    9 280
    Par défaut
    hello WDKyle,

    peux-tu m'expliquer un mystère :
    utilises-tu l'encapsulation de Bass de Patrice pour appeler tes fonctions ? car je ne vois pas dans ses fonctions BASS_RecordSetInput ?
    Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

  14. #14
    Membre éprouvé Avatar de WDKyle
    Homme Profil pro
    Analyste-Programmeur
    Inscrit en
    Septembre 2008
    Messages
    1 200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Analyste-Programmeur

    Informations forums :
    Inscription : Septembre 2008
    Messages : 1 200
    Points : 962
    Points
    962
    Par défaut
    Citation Envoyé par jurassic pork Voir le message
    hello WDKyle,

    peux-tu m'expliquer un mystère :
    utilises-tu l'encapsulation de Bass de Patrice pour appeler tes fonctions ? car je ne vois pas dans ses fonctions BASS_RecordSetInput ?
    Non je suis sous Visual Studio.

  15. #15
    Expert éminent
    Avatar de jurassic pork
    Homme Profil pro
    Bidouilleur
    Inscrit en
    Décembre 2008
    Messages
    3 951
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Bidouilleur
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2008
    Messages : 3 951
    Points : 9 280
    Points
    9 280
    Par défaut
    OK,
    en C ou .NET je suppose. Alors le titre du sujet de la discussion peut prêter à confusion. Pour tes problèmes je te conseille d'aller sur des forums consacrés à BASS.
    Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

  16. #16
    Membre éprouvé Avatar de WDKyle
    Homme Profil pro
    Analyste-Programmeur
    Inscrit en
    Septembre 2008
    Messages
    1 200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Analyste-Programmeur

    Informations forums :
    Inscription : Septembre 2008
    Messages : 1 200
    Points : 962
    Points
    962
    Par défaut
    Citation Envoyé par jurassic pork Voir le message
    OK,
    en C ou .NET je suppose. Alors le titre du sujet de la discussion peut prêter à confusion. Pour tes problèmes je te conseille d'aller sur des forums consacrés à BASS.
    C'est la même façon de faire en .NET ou sous Windev et comme Patrice est bon connaisseur, je pensait que poster ici été judicieux

    J'ai fais pas mal de recherche sur le forum officiel de Bass, je retrouve des problèmes similaire mais pas de solutions.

  17. #17
    Expert éminent
    Avatar de jurassic pork
    Homme Profil pro
    Bidouilleur
    Inscrit en
    Décembre 2008
    Messages
    3 951
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Bidouilleur
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2008
    Messages : 3 951
    Points : 9 280
    Points
    9 280
    Par défaut
    OK, bon courage alors. C'est certainement pas ici que quelqu'un pourra t'aider car ça a l'air plus un problème de BASS que de windev pour le moment.
    Quelle est ta carte son pro ?
    Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

  18. #18
    Membre éprouvé Avatar de WDKyle
    Homme Profil pro
    Analyste-Programmeur
    Inscrit en
    Septembre 2008
    Messages
    1 200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Analyste-Programmeur

    Informations forums :
    Inscription : Septembre 2008
    Messages : 1 200
    Points : 962
    Points
    962
    Par défaut
    Merci jurassik pork,

    Je vais poster un message sur le forum Bass

    Ma carte son est une M-AUDIO Fast Track pro.

  19. #19
    Expert éminent
    Avatar de jurassic pork
    Homme Profil pro
    Bidouilleur
    Inscrit en
    Décembre 2008
    Messages
    3 951
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Bidouilleur
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2008
    Messages : 3 951
    Points : 9 280
    Points
    9 280
    Par défaut
    sinon il y a audacity qui est ton ami
    Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

  20. #20
    Membre éprouvé Avatar de WDKyle
    Homme Profil pro
    Analyste-Programmeur
    Inscrit en
    Septembre 2008
    Messages
    1 200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Analyste-Programmeur

    Informations forums :
    Inscription : Septembre 2008
    Messages : 1 200
    Points : 962
    Points
    962
    Par défaut
    Bonjour,

    Juste pour vous tenir au courant, il y avais un soucis avec la dll bass que j'utilisait. Il est réglé dans la nouvelle version 2.4.10.38

Discussions similaires

  1. Bass.dll / Enregistrement audio
    Par WDKyle dans le forum WinDev
    Réponses: 0
    Dernier message: 28/05/2014, 20h43
  2. Hooker un API(shell32.dll)
    Par sitirna dans le forum C++Builder
    Réponses: 2
    Dernier message: 30/11/2007, 08h59
  3. Cryptage par API advapi32.dll
    Par alexxx69 dans le forum VB 6 et antérieur
    Réponses: 3
    Dernier message: 04/04/2007, 16h27
  4. Réponses: 9
    Dernier message: 29/03/2005, 09h36

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo