Convertire un numero di settori di un CD/DVD in ore,minuti,secondi con le funzioni del API Libdiscid
Da Gambas-it.org - Wikipedia.
Versione del 21 ott 2024 alle 23:40 di Vuott (Discussione | contributi)
Libdiscid è una libreria C per la creazione di un Id disco MusicBrainz e freedb da un CD audio. Essa legge una tabella di contenuti di un CD (TOC) e genera un identificatore che può essere utilizzato per cercare il CD in MusicBrainz.
Per fruire delle sue risorse in Gambas, è necessario installare richiamare la libreria condivisa: "libdiscid.so.0.6.1 ".
Mostriamo un semplice esempio per convertire un numero di settori di un CD/DVD in ore:minuti:secondi:
Private Const SETTORI_PER_SECONDO As Integer = 75 Library "libdiscid:0.6.1" ' DiscId *discid_new() ' Return a handle for a new DiscId object. Private Extern discid_new() As Pointer ' int discid_read_sparse(DiscId *d, const char *device, unsigned int features) ' Read the disc in the given CD-ROM/DVD-ROM drive extracting only the TOC and additionally specified features. Private Extern discid_read_sparse(d As Pointer, device As String, features As Integer) As Integer ' char *discid_get_error_msg(DiscId *d) ' Return a human-readable error message. Private Extern discid_get_error_msg(d As Pointer) As String ' char *discid_get_id(DiscId *d) ' Return a MusicBrainz DiscID. Private Extern discid_get_id(d As Pointer) As String ' char *discid_get_freedb_id(DiscId *d) ' Return a FreeDB DiscID. Private Extern discid_get_freedb_id(d As Pointer) As String ' int discid_get_first_track_num(DiscId *d) ' Return the number of the first track on this disc. Private Extern discid_get_first_track_num(d As Pointer) As Integer ' int discid_get_last_track_num(DiscId *d) ' Return the number of the last audio track on this disc. Private Extern discid_get_last_track_num(d As Pointer) As Integer ' int discid_get_sectors(DiscId *d) ' Return the length of the disc in sectors. Private Extern discid_get_sectors(d As Pointer) As Integer ' int discid_get_track_length(DiscId *d, int track_num) ' Return the length of a track in sectors. Private Extern discid_get_track_length(d As Pointer, track_num As Integer) As Integer ' int discid_get_track_offset(DiscId *d, int track_num) ' Return the sector offset of a track. Private Extern discid_get_track_offset(d As Pointer, track_num As Integer) As Integer ' void discid_free(DiscId *d) ' Release the memory allocated for the DiscId object. Private Extern discid_free(d As Pointer) Public Sub Main() Dim disc, dev As Pointer Dim err, prima_traccia, ultima_traccia As Integer Dim settori, i As Integer Dim durata_in_secondi As Single disc = discid_new() err = discid_read_sparse(disc, Null, 0) If err = 0 Then Error.Raise("Errore: " & discid_get_error_msg(disc)) Print "ID Disco: "; Null, discid_get_id(disc) Print "FreeDB DiscID: "; Null, discid_get_freedb_id(disc) prima_traccia = discid_get_first_track_num(disc) Print "Prima traccia: "; Null, prima_traccia ultima_traccia = discid_get_last_track_num(disc) Print "Ultima traccia: "; Null; ultima_traccia settori = discid_get_sectors(disc) durata_in_secondi = settori / SETTORI_PER_SECONDO Print "Lunghezza: "; Null, settori; " Settori ("; CStr(Time(0, 0, 0, durata_in_secondi * 1000)); ")" Print For i = prima_traccia To ultima_traccia settori = discid_get_track_length(disc, i) Durata_Settori(disc, settori, i) Next discid_free(disc) End Private Procedure Durata_Settori(ds As Pointer, sett As Integer, c As Integer) Dim durata_in_secondi As Single durata_in_secondi = sett / SETTORI_PER_SECONDO Print "Traccia "; c; ":"; Null, discid_get_track_offset(ds, c); Null, sett, " ("; CStr(Time(0, 0, 0, durata_in_secondi * 1000)); ")" End