audioplayer with un4seen bass or sdl2 mixer

User projects written in or related to FreeBASIC.
Post Reply
thrive4
Posts: 70
Joined: Jun 25, 2021 15:32

audioplayer with un4seen bass or sdl2 mixer

Post by thrive4 »

description:
More of a mini app then a project never the less
two versions of a 'meat and potato' audio player
one with un4seen's bass and the other with the
sdl2mixer.

The player has most of the basics in terms of navigation:
press . to play next
press , to play previous
press ] to skip forward 10 secs
press [ to skip backwards 10 secs
press space to pause / play or mute / unmute
press r to restart
press l for linear / shuffle list play
press d for dynamic range compression *note currently not working for sdl
press - to increase volume
press + to decrease volume
press esc to quit

Other basic features are:
- generates a playlist from a folder
- supports most common audio types .mp3, .mp4, .ogg, .wav
> sld2 also supports .flac
- supports playlists .m3u, .pls
- if present cover art is extracted from mp3 and
> written to a thumb file (.jpg or .png)
- ascii interface
- minimal configuration / localization via .ini files

usage:
audioplayer.exe "path to file or folder"
if a file or path is specified the folder will be scanned for an audio file
if the folder has subfolder(s) these will be scanned for audio files as well.

Intended use is mostly educational but might
be useful to some as bare bones audioplayer.

Tested and compiled on windows 7 / 10 as 32bit app

release (32bit windows):
https://github.com/thrive4/app.fb.audio ... s/releases
https://github.com/thrive4/app.fb.audio ... r/releases

source:
https://github.com/thrive4/app.fb.audioplayer-bass
https://github.com/thrive4/app.fb.audioplayer-sdlmixer

requirements:
bass version
bass.dll (32bit)
https://www.un4seen.com/

sdl2 version
sdl2.dll (32bit) v2.0.22.0
https://www.libsdl.org
and
sdl2_mixer.dll (32bit)v2.6.2.0
https://github.com/libsdl-org/SDL_mixer

Note a number of bindings have been added to
SDL2_mixer.bi
located in <FreeBASIC-1.09.0-gcc-9.3>\inc\SDL2\

Either copy the SDL2_mixer.bi included in the source
from
inc\SDL2\
to
<FreeBASIC-1.09.0-gcc-9.3>\inc\SDL2\

or add this to <FreeBASIC-1.09.0-gcc-9.3>\inc\SDL2\SDL2_mixer.bi

Code: Select all

' added for version sdl2 mixer 2.6.2
declare function Mix_GetMusicArtistTag(byval music as Mix_Music ptr) as const zstring ptr
declare function Mix_GetMusicTitleTag(byval music as Mix_Music ptr) as const zstring ptr
declare function Mix_GetMusicAlbumTag(byval music as Mix_Music ptr) as const zstring ptr
declare function Mix_GetMusicCopyrightTag(byval music as Mix_Music ptr) as const zstring ptr
declare function Mix_MusicDuration(byval music as Mix_Music ptr) as double
declare function Mix_GetMusicPosition(byval music as Mix_Music ptr) as double
declare function Mix_GetMusicVolume(byval volume as long) as long
declare function Mix_MasterVolume(byval volume as long) as long

special thanks:
squall4226 for getmp3tag
see viewtopic.php?p=149207&hilit=user+need+ ... um#p149207
rosetta code for compoundtime
https://rosettacode.org/wiki/Convert_se ... #FreeBASIC
Last edited by thrive4 on May 30, 2023 15:07, edited 1 time in total.
thrive4
Posts: 70
Joined: Jun 25, 2021 15:32

Re: audioplayer with un4seen bass or sdl2 mixer

Post by thrive4 »

Added and improved some things see list below.

With regard to 'Dynamic range compression':
https://en.wikipedia.org/wiki/Dynamic_range_compression
'Dynamic range compression (DRC) or simply compression is an audio
signal processing operation that reduces the volume of loud sounds
or amplifies quiet sounds, thus reducing or compressing an audio
signal's dynamic range.'

A poor mans version of the above described functionality
it is only effective with bass due to the support of 'BASS_ChannelGetLevel'
which gets the signal level of the audio which, as far
as I can tell, is not present in sdl_mixer.

The intention is play quiet songs louder play loud
songs not so loud... similar to auto amp in xmplay.

Kinda works but I am playing it by ear so...

Impression code:

Code: Select all

    ' ghetto attempt of dynamic range compression audio
    if drc = "true" and BASS_ChannelIsActive(fx1Handle) = 1 then
        musiclevel = BASS_ChannelGetLevel(fx1Handle)
        ' low amplification
        'drcvolume = 2.0f * sourcevolume - min(-2.0f * sourcevolume, log(max(loWORD(musiclevel), HIWORD(musiclevel)) * 0.0000225f) / log(20))
        ' best for now    
        drcvolume = max(sourcevolume, min(5.0f, 2.0f * sourcevolume - min(-2.0f * sourcevolume, max(-90.0f, log(max(loWORD(musiclevel), HIWORD(musiclevel)) * 0.0000225f)) / log(4.0f))))
        ' volume oscilates noticable
        'drcvolume = 2.0f * sourcevolume - _
        '            min(-2.0f * sourcevolume, log(max(loWORD(musiclevel), HIWORD(musiclevel)) * 0.0000225f) / _
        '            log(4.0f * (max(loWORD(musiclevel), HIWORD(musiclevel))) / 1000.0f))
        BASS_ChannelSetAttribute(fx1Handle, BASS_ATTRIB_VOL, drcvolume)
    else
        BASS_ChannelSetAttribute(fx1Handle, BASS_ATTRIB_VOL, sourcevolume) 
    end if
bass version:
update v1.2 15/05/2023

- added drc, dynamic range compression can be set via conf.ini
- added toggle drc via key 'd' drc on or off
- added toggle listplay via key 'l' shuffle or linear
- added os mixer fader volume control (windows 7 and 10)
| route: sourcevolume > drcvolume (on / off) > currentvolume( is os mixer volume)
| source is set via config, drc amps <n>Db currentvolume is final volume output
- improved command line handling catches incorrect files and paths
- tweaked utilfile.bas more in line with other apps
- tweaked shuffleplay scanning from root dir is not supported
- tieded up code in most files
- fixed .pls

sdl version:
update v1.2 15/05/2023

- added drc, dynamic range compression can be set via conf.ini
| placebo for now on sdl, sdl does not have a mechanism to
| measure signal level of audio as bass does.
- added toggle drc via key 'd' drc on or off (placeholder for now)
- added toggle listplay via key 'l' shuffle or linear
- added os mixer fader volume control (windows 7 and 10)
| route: sourcevolume > drcvolume (on / off) > currentvolume( is os mixer volume)
| source is set via config, drc amps <n>Db currentvolume is final volume output
- improved command line handling catches incorrect files and paths
- tweaked utilfile.bas more in line with other apps
- tweaked shuffleplay scanning from root dir is not supported
- tieded up code in most files
- use init sdl with SDL_Init(SDL_INIT_AUDIO) instead of SDL_Init(SDL_INIT_VIDEO)
| SDL_Init(SDL_INIT_AUDIO) does not block os powerplan to blank display
| note: when using SDL_INIT_VIDEO use SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1")
| respond to power plan settings blank display on windows
| note: set before sdl init (video) otherwise it will not work!
- fixed .pls
Post Reply