Differenze tra le versioni di "Eseguire una traccia di un CD audio con le funzioni esterne del API di libcdio e di ALSA"

Da Gambas-it.org - Wikipedia.
(Creata pagina con " Library "libcdio:13.0.0" Private Enum DRIVER_UNKNOWN = 0, DRIVER_AIX, DRIVER_BSDI, DRIVER_FREEBSD, DRIVER_NETBSD, DRIVER_LINUX, DRIVER_SOLARIS, DRIVER_OS2, D...")
 
Riga 13: Riga 13:
 
  ' ''Get the number of tracks on the CD.''</font>
 
  ' ''Get the number of tracks on the CD.''</font>
 
  Private Extern cdio_get_num_tracks(p_cdio As Pointer) As Byte
 
  Private Extern cdio_get_num_tracks(p_cdio As Pointer) As Byte
+
 
<FONT Color=gray>' ''track_t cdio_get_first_track_num(const CdIo_t * p_cdio)''
 
' ''Get the number of the first track.''</font>
 
Private Extern cdio_get_first_track_num(p_cdio As Pointer) As Byte
 
 
 
  <FONT Color=gray>' ''lsn_t cdio_get_track_lsn(const CdIo_t * p_cdio, track_t u_track)''
 
  <FONT Color=gray>' ''lsn_t cdio_get_track_lsn(const CdIo_t * p_cdio, track_t u_track)''
 
  ' ''Return the starting LSN for track number i_track in p_cdio.''</font>
 
  ' ''Return the starting LSN for track number i_track in p_cdio.''</font>
Riga 65: Riga 61:
 
   
 
   
 
   Dim cd As Pointer
 
   Dim cd As Pointer
   Dim traccia, tracce, prima_traccia As Byte
+
   Dim traccia, tracce, i As Byte
  Dim i, j As Integer
 
 
   Dim lsn As New Integer[]
 
   Dim lsn As New Integer[]
 
   Dim esec As String
 
   Dim esec As String
 
    
 
    
 
  <FONT Color=gray>' ''Viene impostato il numero della traccia da eseguire:''</font>
 
  <FONT Color=gray>' ''Viene impostato il numero della traccia da eseguire:''</font>
   traccia = 11
+
   traccia = 4
 
    
 
    
 
   cd = cdio_open(Null, DRIVER_LINUX)
 
   cd = cdio_open(Null, DRIVER_LINUX)
Riga 77: Riga 72:
 
    
 
    
 
   tracce = cdio_get_num_tracks(cd)
 
   tracce = cdio_get_num_tracks(cd)
  i = CInt(cdio_get_first_track_num(cd))
+
   Print "Tracce del CD-Audio (1 - "; tracce; ")"
  prima_traccia = i
 
   Print "Tracce del CD-Audio ("; prima_traccia; " - "; prima_traccia + tracce - 1; ")"
 
 
   Print " #:  Durata"
 
   Print " #:  Durata"
   For j = 0 To tracce - 1
+
<FONT Color=gray>' ''Individua l'indirizzo del settore logico di ciascuna traccia:''</font>
 +
   For i = 0 To tracce - 1
 
     lsn.Push(cdio_get_track_lsn(cd, i))
 
     lsn.Push(cdio_get_track_lsn(cd, i))
    Inc i
 
 
   Next
 
   Next
 
   lsn.Push(cdio_get_track_lsn(cd, CDIO_CDROM_LEADOUT_TRACK))
 
   lsn.Push(cdio_get_track_lsn(cd, CDIO_CDROM_LEADOUT_TRACK))
   For j = 0 To tracce - 1
+
   For i = 0 To tracce - 1
     If j + 1 = traccia Then esec = "< in esecuzione"
+
     If i + 1 = traccia Then esec = "< in esecuzione"
     If (CDIO_INVALID_LSN <> lsn[j]) Then
+
     If (CDIO_INVALID_LSN <> lsn[i]) Then
       Print Format(j + 1, "#0:"), Date(0, 0, 0, 0, 0, 0, ((((lsn[j + 1] - lsn[j]) * 2352) * 8) / 1411200) * 1000), esec
+
       Print Format(i + 1, "#0:"), Date(0, 0, 0, 0, 0, 0, ((((lsn[i + 1] - lsn[i]) * 2352) * 8) / 1411200) * 1000), esec
 
     Endif
 
     Endif
 
     esec = Null
 
     esec = Null
Riga 132: Riga 125:
 
      
 
      
 
  '''End'''
 
  '''End'''
 +
 +
 +
 +
 +
=Riferimenti=
 +
* http://www.gnu.org/software/libcdio/
 +
* http://www.gnu.org/software/libcdio/libcdio.html
 +
* http://www.alsa-project.org/alsa-doc/alsa-lib/pcm.html
 +
* https://en.wikipedia.org/wiki/Compact_Disc_Digital_Audio
 +
* http://www.jmargolin.com/project/cdtermw.pdf
 +
* http://whatis.techtarget.com/reference/Fast-Guide-to-CD-DVD
  
  

Versione delle 05:33, 17 apr 2016

Library "libcdio:13.0.0"

Private Enum DRIVER_UNKNOWN = 0, DRIVER_AIX, DRIVER_BSDI, DRIVER_FREEBSD, DRIVER_NETBSD, DRIVER_LINUX, DRIVER_SOLARIS,
             DRIVER_OS2, DRIVER_OSX, DRIVER_WIN32, DRIVER_CDRDAO, DRIVER_BINCUE, DRIVER_NRG, DRIVER_DEVICE
Private Const CDIO_INVALID_LSN As Integer = -45301
Private Const CDIO_CDROM_LEADOUT_TRACK As Integer = &AA

' CdIo_t * cdio_open (const char *psz_source, driver_id_t driver_id)
' Sets up to read from place specified by psz_source and driver_id.
Private Extern cdio_open(psz_source As String, driver_id As Integer) As Pointer

' track_t cdio_get_num_tracks(const CdIo_t * p_cdio)
' Get the number of tracks on the CD.
Private Extern cdio_get_num_tracks(p_cdio As Pointer) As Byte
 
' lsn_t cdio_get_track_lsn(const CdIo_t * p_cdio, track_t u_track)
' Return the starting LSN for track number i_track in p_cdio.
Private Extern cdio_get_track_lsn(p_cdio As Pointer, u_track As Integer) As Integer

' driver_return_code_t cdio_read_audio_sector (const CdIo_t *p_cdio, void *p_buf, lsn_t i_lsn)
' Read an audio sector.
Private Extern cdio_read_audio_sector(p_cdio As Pointer, p_buf As Byte[], i_lsn As Integer) As Integer

' void cdio_destroy(CdIo_t * p_cdio)
' Free any resources associated with p_cdio.
Private Extern cdio_destroy(p_cdio As Pointer)


Library "libasound:2"

Private Const SND_PCM_STREAM_PLAYBACK As Integer = 0
Private Const SND_PCM_FORMAT_S16_LE As Integer = 2
Private Const SND_PCM_ACCESS_RW_INTERLEAVED As Integer = 3

' int snd_pcm_open (snd_pcm_t **pcm, const char *name, snd_pcm_stream_t stream, int mode)
' Opens a PCM.
Private Extern snd_pcm_open(pcm As Pointer, nome As String, stream As Integer, mode As Integer) As Integer

' const char * snd_strerror (int errnum)
' Returns the message for an Error code.
Private Extern snd_strerror(errnum As Integer) As String

' int snd_pcm_set_params (snd_pcm_t *pcm, snd_pcm_format_t format, snd_pcm_access_t access, unsigned int canali, unsigned int rate, int soft_resample, unsigned int latency)
' Set the hardware and software parameters in a simple way.
Private Extern snd_pcm_set_params(pcm As Pointer, formatI As Integer, accessI As Integer, channels As Integer, rate As Integer, soft_resample As Integer, latency As Integer) As Integer

' snd_pcm_sframes_t snd_pcm_writei (snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size)
' Write interleaved frames to a PCM.
Private Extern snd_pcm_writei(pcm As Pointer, buffer As Pointer, uframes As Long) As Integer

' int snd_pcm_drain (snd_pcm_t *pcm)
' Stop a PCM preserving pending frames.
Private Extern snd_pcm_drain(pcm As Pointer) As Integer

' int snd_pcm_close (snd_pcm_t *pcm)
' Close PCM handle.
Private Extern snd_pcm_close(pcm As Pointer) As Integer


Public Sub Main()

 Dim cd As Pointer
 Dim traccia, tracce, i As Byte
 Dim lsn As New Integer[]
 Dim esec As String
 
' Viene impostato il numero della traccia da eseguire:
  traccia = 4
 
  cd = cdio_open(Null, DRIVER_LINUX)
  If cd = 0 Then Error.Raise("Impossibile trovare il driver per il cd-audio !")
  
  tracce = cdio_get_num_tracks(cd)
  Print "Tracce del CD-Audio (1 - "; tracce; ")"
  Print " #:  Durata"
' Individua l'indirizzo del settore logico di ciascuna traccia:
  For i = 0 To tracce - 1
    lsn.Push(cdio_get_track_lsn(cd, i))
  Next
  lsn.Push(cdio_get_track_lsn(cd, CDIO_CDROM_LEADOUT_TRACK))
  For i = 0 To tracce - 1
    If i + 1 = traccia Then esec = "< in esecuzione"
    If (CDIO_INVALID_LSN <> lsn[i]) Then
      Print Format(i + 1, "#0:"), Date(0, 0, 0, 0, 0, 0, ((((lsn[i + 1] - lsn[i]) * 2352) * 8) / 1411200) * 1000), esec
    Endif
    esec = Null
  Next
  
  lsn.Push(cdio_get_track_lsn(cd, CDIO_CDROM_LEADOUT_TRACK))
  
  Esecuzione(cd, lsn, traccia)
   
' Va in chiusura:
  cdio_destroy(cd)
   
End
  
  
Private Procedure Esecuzione(pcd As Pointer, sett As Integer[], tr As Byte)
  
 Dim handle As Pointer
 Dim err, frames, somma_frames, i As Integer
 Dim buf As Byte[]
  
  err = snd_pcm_open(VarPtr(handle), "default", SND_PCM_STREAM_PLAYBACK, 0)
  If err < 0 Then Error.Raise("Errore nell'apertura del subsistema PCM: " & snd_strerror(err))
  
  err = snd_pcm_set_params(handle, SND_PCM_FORMAT_S16_LE, SND_PCM_ACCESS_RW_INTERLEAVED, 2, 44100, 1, 500000)
  If err < 0 Then Error.Raise("Errore nell'impostazione dei parametri audio: " & snd_strerror(err))
  
  buf = New Byte[2352]
  
  For i = 0 To (sett[tr] - sett[tr - 1]) - 1
    cdio_read_audio_sector(pcd, buf, sett[tr - 1] + i)
    frames = snd_pcm_writei(handle, buf.Data, 2352 / 4)
    somma_frames += frames
    Write #File.Out, "\rTempo trascorso: " & Date(0, 0, 0, 0, 0, 0, (somma_frames / 44100) * 1000) 
  Next
  
  snd_pcm_drain(handle)
  
' Alla fine dell'esecuzione chiude il subsistema PCM:
  err = snd_pcm_close(handle)
  If err = 0 Then Print "\nChiusura dell'interfaccia PCM: regolare."
    
End



Riferimenti



Pagina in costruzione !