Skip to content

Commit

Permalink
update v1.6 20/09/2024
Browse files Browse the repository at this point in the history
- getuilabelvalue implemented full automatic spacing
- added generate m3u by searching on one tag
  artist, title, album, genre and year
  audioplayer <audiosource> <tag> <tagquery>
  example: audioplayer.exe g:\data\mp3\classic artist beethoven
  generates the m3u file beethoven.m3u
  which then can be played by audioplayer.exe beethoven.m3u
  notes:
  * simple search so 195 is equivelant of ?195? or *195*
  * runtime in seconds is not calculated default is #EXTINF:134
  * no explicit wildcard support
- tweaked getmp3tag increase speed parsing mp3 tags
- trimmed utilfile.bas
- fixed .pls parsing and playback
- update sdl2       from 2.26.5.0 to 2.30.7.0
- update sdl2_mixer from 2.6.2.0 to 2.8.0.0
  • Loading branch information
thrive4 authored Sep 20, 2024
1 parent f2cbe19 commit 3fce904
Show file tree
Hide file tree
Showing 6 changed files with 410 additions and 174 deletions.
82 changes: 82 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
## audioplayer (sdl2 mixer)
basic audioplayer written in freebasic and sdl_mixer\
* supported audio types are .flac, .mp3, .m4a, .mp4, .ogg, .wav
* supported playlists .m3u, .pls
* ascii interface

if present coverart will be extracted and written to file as thumb.jpg\
When a file or path is specified the current dir and sub dir(s)\
will be scanned for audio file(s) which will generate an internal playlist
## 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.

generate .m3u: audioplayer "path to file or folder" "tag" "tagquery"\
example: audioplayer.exe g:\data\mp3\classic artist beethoven\
generates the m3u file beethoven.m3u\
which then can be played by audioplayer.exe beethoven.m3u
* simple search so 195 is equivelant of ?195? or \*195*
* runtime in seconds is not calculated default is #EXTINF:134
* no explicit wildcard support, only searchs on one tag
* supported tags artist, title, album, genre and year
## configuration
basic config options in conf.ini\
locale = <en, de, fr, nl>\
defaultvolume = <1 .. 128>\
playtype = <shuffle, linear>\
' dynamic range compression *currently not working with sdl\
drc = <true, false>
## requirements
sdl2.dll (32bit)\
https://www.libsdl.org/
and\
sdl2_mixer.dll (32bit)\
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

>' 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

## performance
windows 7 / windows 10(1903)\
ram usage ~2MB / 2MB\
handles ~120 / ~200\
threads 4 / 7\
cpu ~1 (low) / ~2\
tested on intel i5-6600T
## 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
# special thanks to
squall4226 for getmp3tag\
see https://www.freebasic.net/forum/viewtopic.php?p=149207&hilit=user+need+TALB+for+album#p149207
rosetta code for compoundtime\
https://rosettacode.org/wiki/Convert_seconds_to_compound_duration#FreeBASIC
8 changes: 4 additions & 4 deletions app.rc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ FB_PROGRAM_ICON ICON "f:\dev\freebasic\projects\audioplayer-sdlmixer\app.ico"

// add version and file info in exe windows only
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1, 5, 0, 000
PRODUCTVERSION 1, 5, 0, 0
FILEVERSION 1, 6, 0, 000
PRODUCTVERSION 1, 6, 0, 0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x9L
Expand All @@ -29,13 +29,13 @@ BEGIN
VALUE "Comments", "needs sdl2 and sdl2 mixer libs"
VALUE "CompanyName", ""
VALUE "FileDescription", "audioplayer with sdl2 mixer"
VALUE "FileVersion", "1, 5, 0, 000"
VALUE "FileVersion", "1, 6, 0, 000"
VALUE "InternalName", ""
VALUE "LegalCopyright", ""
VALUE "OriginalFilename", "audioplayer"
VALUE "PrivateBuild", ""
VALUE "ProductName", "audioplayer"
VALUE "ProductVersion", "1, 5, 0, 0"
VALUE "ProductVersion", "1, 6, 0, 0"
END
END
BLOCK "VarFileInfo"
Expand Down
127 changes: 66 additions & 61 deletions audioplayer.bas
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ else
logentry("fatal", imagefolder + " does not excist or is incorrect")
end if
end if
if instr(command(1), ".m3u") = 0 and instr(command(1), ".pls") = 0 then
if instr(command(1), ".m3u") = 0 and instr(command(1), ".pls") = 0 and len(command(2)) = 0 then
maxitems = createlist(imagefolder, filetypes, "music")
filename = listplay(playtype, "music")
end if
Expand All @@ -129,6 +129,70 @@ if instr(command(1), ".") <> 0 and instr(command(1), ".m3u") = 0 and instr(comma
currentsong = setcurrentlistitem("music", command(1))
end if

' search with query and export .m3u
if instr(command(1), ":") <> 0 and len(command(2)) <> 0 then
select case command(2)
case "artist"
case "title"
case "album"
case "year"
case "genre"
case else
logentry("fatal", "unknown tag '" & command(2) & "' valid tags artist, title, album, genre and year")
end select

maxitems = exportm3u(command(1), "*.mp3", "m3u", "exif", command(2), command(3))
filename = getmp3playlist(exepath + "\" + command(3) + ".m3u")
currentsong = setcurrentlistitem("music", filename)
if currentsong = 1 then
logentry("fatal", "no matches found for " + command(3) + " in " + command(2))
end if
end if

if instr(command(1), ".pls") <> 0 or instr(command(1), ".m3u") <> 0 then
filename = command(1)
Open filename For input As 1
open exepath + "\music.tmp" for output as 2
itemnr = 0
Do Until EOF(1)
Line Input #1, listitem
' ghetto parsing pls
if instr(listitem, "=") > 0 and instr(command(1), ".pls") <> 0 then
select case true
case instr(listitem, "file") > 0
print #2, mid(listitem, instr(listitem, "=") + 1, len(listitem))
case instr(listitem, "title") > 0
case instr(listitem, "length") > 0
listduration = listduration + val(mid(listitem, instr(listitem, "=") + 1, len(listitem)))
itemnr += 1
case len(listitem) = 0
'nop
case else
'msg64 = msg64 + listitem
end select
end if
' ghetto parsing m3u
if len(listitem) > 0 and instr(command(1), ".m3u") <> 0 then
select case true
case instr(listitem, "EXTINF:") > 0
listduration = listduration + val(mid(listitem, instr(listitem, ":") + 1, len(instr(listitem, ","))- 1))
itemnr += 1
case instr(listitem, ".") > 0
print #2, listitem
case len(listitem) = 0
'nop
case else
'msg64 = msg64 + listitem
end select
end if
Loop
maxitems = itemnr
close
filename = getmp3playlist(command(1))
currentsong = setcurrentlistitem("music", filename)
logentry("notice", "parsing and playing plylist " + filename)
end if

initsdl:
' init audio
' note normaly init video is used but sdl blocks display timeout via powerplan of the os
Expand Down Expand Up @@ -176,60 +240,6 @@ function compoundtime(m As Long) as string
return dummy
End function

if instr(command(1), ".pls") <> 0 then
filename = command(1)
Open filename For input As 1
open "music.tmp" for output as 2
itemnr = 0
Do Until EOF(1)
Line Input #1, listitem
' ghetto parsing pls
if instr(listitem, "=") > 0 then
select case true
case instr(listitem, "numberofentries") > 0
maxitems = val(mid(listitem, instr(listitem, "=") + 1, len(listitem)))
case instr(listitem, "file" + str(itemnr)) > 0
print #2, mid(listitem, instr(listitem, "=") + 1, len(listitem))
case instr(listitem, "title" + str(itemnr)) > 0
case instr(listitem, "length" + str(itemnr)) > 0
listduration = listduration + val(mid(listitem, instr(listitem, "=") + 1, len(listitem)))
itemnr += 1
case len(listitem) = 0
'nop
case else
'msg64 = msg64 + listitem
end select
end if
Loop
close
end if

if instr(command(1), ".m3u") <> 0 then
filename = command(1)
Open filename For input As 1
open "music.tmp" for output as 2
itemnr = 0
Do Until EOF(1)
Line Input #1, listitem
' ghetto parsing m3u
if len(listitem) > 0 then
select case true
case instr(listitem, "EXTINF:") > 0
listduration = listduration + val(mid(listitem, instr(listitem, ":") + 1, len(instr(listitem, ","))- 1))
itemnr += 1
case instr(listitem, ".") > 0
print #2, listitem
case len(listitem) = 0
'nop
case else
'msg64 = msg64 + listitem
end select
end if
Loop
maxitems = itemnr
close
end if

' listduration for recursive scan dir
if maxitems > 1 and instr(command(1), ".m3u") = 0 and instr(command(1), ".pls") = 0 then
dim tmp as long
Expand Down Expand Up @@ -341,7 +351,6 @@ end function

' init playback
dim refreshinfo as boolean = true
dim taginfo(1 to 5) as string
dim firstmp3 as integer = 1
dim musiclevel as single
dim maxlevel as single
Expand Down Expand Up @@ -489,11 +498,7 @@ Do
Print
' tag info
if refreshinfo = true and instr(filename, ".mp3") <> 0 then
taginfo(1) = getmp3tag("artist",filename)
taginfo(2) = getmp3tag("title", filename)
taginfo(3) = getmp3tag("album", filename)
taginfo(4) = getmp3tag("year", filename)
taginfo(5) = getmp3tag("genre", filename)
getmp3baseinfo(filename)
refreshinfo = false
end if
getuilabelvalue("artist", taginfo(1))
Expand Down
18 changes: 18 additions & 0 deletions audioplayer.nfo
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
update v1.6 20/09/2024
- getuilabelvalue implemented full automatic spacing
- added generate m3u by searching on one tag
artist, title, album, genre and year
audioplayer <audiosource> <tag> <tagquery>
example: audioplayer.exe g:\data\mp3\classic artist beethoven
generates the m3u file beethoven.m3u
which then can be played by audioplayer.exe beethoven.m3u
notes:
* simple search so 195 is equivelant of ?195? or *195*
* runtime in seconds is not calculated default is #EXTINF:134
* no explicit wildcard support
- tweaked getmp3tag increase speed parsing mp3 tags
- trimmed utilfile.bas
- fixed .pls parsing and playback
- update sdl2 from 2.26.5.0 to 2.30.7.0
- update sdl2_mixer from 2.6.2.0 to 2.8.0.0

update v1.5 24/11/2023
- corrected freefile variable type to long
integer causes issues when opening multiple
Expand Down
Binary file modified audioplayer.wfbe
Binary file not shown.
Loading

0 comments on commit 3fce904

Please sign in to comment.