[rubyripper] 2 new revisions pushed by boukewou...@gmail.com on 2013-01-09 22:12 GMT

2 views
Skip to first unread message

rubyr...@googlecode.com

unread,
Jan 9, 2013, 5:12:56 PM1/9/13
to rubyrippe...@googlegroups.com
2 new revisions:

Revision: c94ca2a19912
Author: Bouke Woudstra <boukew...@gmail.com>
Date: Wed Jan 9 14:10:49 2013
Log: Don't assign a tracknumber for the image rip file.
http://code.google.com/p/rubyripper/source/detail?r=c94ca2a19912

Revision: 5f9defa8eb9a
Author: Bouke Woudstra <boukew...@gmail.com>
Date: Wed Jan 9 14:11:49 2013
Log: Refactor some code regarding the audio constants and conversion.
http://code.google.com/p/rubyripper/source/detail?r=5f9defa8eb9a

==============================================================================
Revision: c94ca2a19912
Author: Bouke Woudstra <boukew...@gmail.com>
Date: Wed Jan 9 14:10:49 2013
Log: Don't assign a tracknumber for the image rip file.

http://code.google.com/p/rubyripper/source/detail?r=c94ca2a19912

Modified:
/lib/rubyripper/codecs/main.rb
/spec/codecs/main_spec.rb

=======================================
--- /lib/rubyripper/codecs/main.rb Tue Jan 8 10:37:08 2013
+++ /lib/rubyripper/codecs/main.rb Wed Jan 9 14:10:49 2013
@@ -124,7 +124,7 @@
when :encoder then add(value, "\"Rubyripper #{$rr_version}\"")
when :cuesheet then addCuesheet(value) if @prefs.image
when :trackname then add(value, @tags.trackname(track)) unless
@prefs.image
- when :tracknumber then add(value, "#{track}")
+ when :tracknumber then add(value, "#{track}") unless @prefs.image
when :tracktotal then add(value, "#{@disc.audiotracks}")
when :tracknumberTotal then
add(value, "#{track}/#{@disc.audiotracks}")
end
=======================================
--- /spec/codecs/main_spec.rb Thu Sep 27 13:32:05 2012
+++ /spec/codecs/main_spec.rb Wed Jan 9 14:10:49 2013
@@ -53,6 +53,7 @@
context "When calculating the command for encoding a track" do
before(:each) do
prefs.should_receive(:settingsMp3).and_return '-V 2'
+ prefs.stub(:image).and_return false

scheme.should_receive(:getTempFile).with(1).and_return 'input_1.wav'
scheme.should_receive(:getFile).with('mp3',
1).and_return '/home/mp3/1-test.mp3'
disc.should_receive(:audiotracks).and_return 99
@@ -115,6 +116,7 @@

it "should calculate the command for encoding" do
prefs.should_receive(:settingsVorbis).and_return '-q 6'
+ prefs.stub(:image).and_return false
scheme.should_receive(:getTempFile).with(1).and_return 'input_1.wav'
scheme.should_receive(:getFile).with('vorbis',
1).and_return '/home/vorbis/1-test.ogg'
disc.should_receive(:audiotracks).and_return 99
@@ -145,9 +147,9 @@
@codec.replaygainAlbum.should == 'metaflac
--add-replay-gain "/home/flac"/*.flac'
end

- it "should calculate the command for encoding" do
+ it "should calculate the command for encoding a track" do
prefs.should_receive(:settingsFlac).and_return '-q 6'
- prefs.should_receive(:createCue).and_return false
+ prefs.stub(:image).and_return false
scheme.should_receive(:getTempFile).with(1).and_return 'input_1.wav'
scheme.should_receive(:getFile).with('flac',
1).and_return '/home/flac/1-test.flac'
disc.should_receive(:audiotracks).and_return 99
@@ -163,8 +165,9 @@
@codec.setTagsAfterEncoding(1).should == ''
end

- it "should save the cuesheet file if available" do
+ it "should save the cuesheet file if available for image rips" do
prefs.should_receive(:settingsFlac).and_return '-q 6'
+ prefs.stub(:image).and_return true
prefs.should_receive(:createCue).and_return true
scheme.should_receive(:getCueFile).and_return '/home/flac/test.cue'
file.should_receive(:exist?).with('/home/flac/test.cue').and_return
true
@@ -178,7 +181,7 @@
@codec.command(1).should == 'flac -o "/home/flac/1-test.flac" -q 6
--tag '\
'ARTIST="trackArtist 1" --tag ALBUM="album" --tag GENRE="genre"
--tag DATE="year" '\
'--tag "ALBUM ARTIST"="artist" --tag DISCNUMBER=1 --tag
ENCODER="Rubyripper test" '\
- '--tag DISCID="ABCDEFGH" --tag TITLE="trackname 1" --tag
TRACKNUMBER=1 --tag '\
+ '--tag DISCID="ABCDEFGH" --tag '\
'TRACKTOTAL=99 --cuesheet="/home/flac/test.cue" "input_1.wav"'
end
end
@@ -223,6 +226,7 @@

it "should calculate the command for encoding and tagging" do
prefs.should_receive(:settingsNero).and_return '-q 1'
+ prefs.stub(:image).and_return false
scheme.should_receive(:getTempFile).with(1).and_return 'input_1.wav'
scheme.should_receive(:getFile).with('nero',
1).twice.and_return '/home/nero/1-test.m4a'
disc.should_receive(:audiotracks).and_return 99
@@ -250,8 +254,9 @@
@codec.replaygainAlbum.should == ''
end

- it "should calculate the command for encoding" do
+ it "should calculate the command for encoding an image rip" do
prefs.should_receive(:settingsWavpack).and_return ''
+ prefs.stub(:image).and_return true
prefs.should_receive(:createCue).and_return true

scheme.should_receive(:getCueFile).and_return '/home/wavpack/test.cue'

file.should_receive(:exist?).with('/home/wavpack/test.cue').and_return true
@@ -264,7 +269,7 @@

@codec.command(1).should == 'wavpack -w ARTIST="trackArtist 1" -w
ALBUM="album" '\
'-w GENRE="genre" -w DATE="year" -w "ALBUM ARTIST"="artist" -w
DISCNUMBER=1 -w '\
- 'ENCODER="Rubyripper test" -w DISCID="ABCDEFGH" -w
TITLE="trackname 1" -w TRACKNUMBER=1 -w '\
+ 'ENCODER="Rubyripper test" -w DISCID="ABCDEFGH" -w '\
'TRACKTOTAL=99 -w
CUESHEET="/home/wavpack/test.cue" "input_1.wav"
-o "/home/wavpack/1-test.wv"'
@codec.setTagsAfterEncoding(1).should == ''
end
@@ -277,6 +282,7 @@

it "should calculate the command for encoding" do
prefs.should_receive(:settingsOpus).and_return '--bitrate 160'
+ prefs.stub(:image).and_return false
scheme.should_receive(:getTempFile).with(1).and_return 'input_1.wav'
scheme.should_receive(:getFile).with('opus',
1).and_return '/home/opus/1-test.opus'
disc.should_receive(:audiotracks).and_return 99

==============================================================================
Revision: 5f9defa8eb9a
Author: Bouke Woudstra <boukew...@gmail.com>
Date: Wed Jan 9 14:11:49 2013
Log: Refactor some code regarding the audio constants and conversion.

http://code.google.com/p/rubyripper/source/detail?r=5f9defa8eb9a

Added:
/lib/rubyripper/modules/audioCalculations.rb
Modified:
/lib/rubyripper/calcPeakLevel.rb
/lib/rubyripper/disc/cuesheet.rb
/lib/rubyripper/disc/scanDiscCdcontrol.rb
/lib/rubyripper/disc/scanDiscCdinfo.rb
/lib/rubyripper/disc/scanDiscCdparanoia.rb
/lib/rubyripper/disc/scanDiscCdrdao.rb
/lib/rubyripper/log.rb
/lib/rubyripper/rippingInfoAtStart.rb
/lib/rubyripper/secureRip.rb
/lib/rubyripper/system/fileHash.rb
/lib/rubyripper/waveFile.rb
/spec/disc/scanDiscCdcontrol_spec.rb
/spec/disc/scanDiscCdinfo_spec.rb

=======================================
--- /dev/null
+++ /lib/rubyripper/modules/audioCalculations.rb Wed Jan 9 14:11:49 2013
@@ -0,0 +1,56 @@
+#!/usr/bin/env ruby
+# Rubyripper - A secure ripper for Linux/BSD/OSX
+# Copyright (C) 2007 - 2010 Bouke Woudstra (boukew...@gmail.com)
+#
+# This file is part of Rubyripper. Rubyripper is free software: you can
+# redistribute it and/or modify it under the terms of the GNU General
+# Public License as published by the Free Software Foundation, either
+# version 3 of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>
+
+# A shared module for all kinds of audio calculations and standard values
+module AudioCalculations
+
+ # Wave files have 75 audio frames for each second
+ FRAMES_A_SECOND = 75
+
+ # That makes up 60x75 frames for each minute
+ FRAMES_A_MINUTE = 60 * FRAMES_A_SECOND
+
+ # The maximum decibel level that 16-bits audio can contain
+ MAX_DECIBEL_LEVEL_16_BIT = 96.0
+
+ # The overhead of the .wav container (info about stereo vs mono, khz,
etcetera)
+ BYTES_WAV_CONTAINER = 44
+
+ # Amount of bits a second for audio disc is 44100 (herz) * 16 (bits) * 2
(stereo) = 1411200
+ # Amount of bytes a second is 1411200 / 8 = 176400
+ # Amount of bytes a frame is 176400 / 75 = 2352
+ BYTES_AUDIO_FRAME = 2352
+ BYTES_AUDIO_SECOND = 2352 * FRAMES_A_SECOND
+
+ # minutes:seconds:sectors to sectors
+ def toSectors(time)
+ minutes, seconds, sectors = time.split(':')
+ count = sectors.to_i
+ count += (seconds.to_i * FRAMES_A_SECOND)
+ count += (minutes.to_i * FRAMES_A_MINUTE)
+ return count
+ end
+
+ # sectors to mm:ss:ff
+ def toTime(sectors)
+ return '' if sectors == nil
+ minutes = sectors / (FRAMES_A_MINUTE)
+ seconds = ((sectors % (FRAMES_A_MINUTE)) / FRAMES_A_SECOND)
+ frames = sectors - minutes * FRAMES_A_MINUTE - seconds *
FRAMES_A_SECOND
+ return "%02d:%02d:%02d" % [minutes, seconds, frames]
+ end
+end
=======================================
--- /lib/rubyripper/calcPeakLevel.rb Tue Dec 18 10:27:10 2012
+++ /lib/rubyripper/calcPeakLevel.rb Wed Jan 9 14:11:49 2013
@@ -17,11 +17,11 @@

require 'rubyripper/system/dependency'
require 'rubyripper/system/execute'
+require 'rubyripper/modules/audioCalculations'

# This class calculates the loudness of the file
class CalcPeakLevel
- MAX_DECIBEL_LEVEL_16_BIT = 96.0
- BYTES_WAV_CONTAINER = 44 # to store the type of wav file
+ include AudioCalculations

def initialize(exec=nil, deps=nil, prefs=nil)
@exec = exec ? exec : Execute.new()
=======================================
--- /lib/rubyripper/disc/cuesheet.rb Wed Jan 2 12:15:42 2013
+++ /lib/rubyripper/disc/cuesheet.rb Wed Jan 9 14:11:49 2013
@@ -26,11 +26,11 @@
require 'rubyripper/system/fileAndDir'
require 'rubyripper/preferences/main'
require 'rubyripper/system/dependency'
+require 'rubyripper/modules/audioCalculations'

class Cuesheet
+ include AudioCalculations

- FRAMES_A_SECOND = 75
- FRAMES_A_MINUTE = 60 * FRAMES_A_SECOND
HIDDEN_FIRST_TRACK = 0
FIRST_TRACK = 1

@@ -66,13 +66,6 @@
codec == 'mp3' ? 'MP3' : 'WAVE'
end

- def time(sector) # minutes:seconds:leftover frames
- minutes = sector / FRAMES_A_MINUTE
- seconds = (sector % FRAMES_A_MINUTE) / FRAMES_A_SECOND
- frames = sector % FRAMES_A_SECOND
- return "#{sprintf("%02d", minutes)}:#{sprintf("%02d",
seconds)}:#{sprintf("%02d", frames)}"
- end
-
def printDiscData
@cuesheet << "REM GENRE #{@md.genre}"
@cuesheet << "REM DATE #{@md.year}"
@@ -117,19 +110,19 @@

# print a line for the index of a track
def printIndexLine(index, sector)
- @cuesheet << " INDEX #{index} #{time(sector)}"
+ @cuesheet << " INDEX #{index} #{toTime(sector)}"
end

def aHiddenTrackIsRipped
- hiddenSectorsInMinutes = @disc.getStartSector(FIRST_TRACK) /
FRAMES_A_SECOND
- @prefs.image == false && @prefs.ripHiddenAudio == true &&
hiddenSectorsInMinutes >= @prefs.minLengthHiddenTrack
+ hiddenSectorsInSeconds = @disc.getStartSector(FIRST_TRACK) /
FRAMES_A_SECOND
+ @prefs.image == false && @prefs.ripHiddenAudio == true &&
hiddenSectorsInSeconds >= @prefs.minLengthHiddenTrack
end

# if the hidden audio is not prepended to the file, only write a pregap
tag
def printPregapForHiddenTrack
if (@prefs.ripHiddenAudio == false || aHiddenTrackIsRipped()) &&
@disc.getStartSector(FIRST_TRACK) > 0
- @cuesheet << " PREGAP #{time(@disc.getStartSector(FIRST_TRACK))}"
+ @cuesheet << " PREGAP
#{toTime(@disc.getStartSector(FIRST_TRACK))}"
end
end

=======================================
--- /lib/rubyripper/disc/scanDiscCdcontrol.rb Tue Jun 5 18:28:06 2012
+++ /lib/rubyripper/disc/scanDiscCdcontrol.rb Wed Jan 9 14:11:49 2013
@@ -17,6 +17,7 @@

require 'rubyripper/preferences/main'
require 'rubyripper/system/execute'
+require 'rubyripper/modules/audioCalculations'

# A class that interprets the toc with the info of cdcontrol (from
# FreeBSD) Quite reliable for detecting data tracks and can even
@@ -25,6 +26,8 @@
# discs with data tracks. For freedb calculation cdcontrol is correct, for
# detecting the audio part, cdparanoia is correct.
class ScanDiscCdcontrol
+ include AudioCalculations
+
attr_reader :status, :totalSectors, :playtime, :audiotracks,
:firstAudioTrack, :dataTracks

@@ -81,15 +84,6 @@
return @status.nil?
end

- # now back to time
- def toTime(sectors)
- return '' if sectors == nil
- minutes = sectors / (60*75)
- seconds = ((sectors % (60*75)) / 75)
- frames = sectors - minutes*60*75 - seconds*75
- return "%02d:%02d.%02d" % [minutes, seconds, frames]
- end
-
# store the info of the query in variables
def parseQuery(query)
tracknumber = 0
=======================================
--- /lib/rubyripper/disc/scanDiscCdinfo.rb Sun Mar 25 10:33:43 2012
+++ /lib/rubyripper/disc/scanDiscCdinfo.rb Wed Jan 9 14:11:49 2013
@@ -17,6 +17,7 @@

require 'rubyripper/system/execute'
require 'rubyripper/preferences/main'
+require 'rubyripper/modules/audioCalculations'

# A class that interprets the toc with the info of cd-info
# Quite reliable for detecting data tracks and generating freedb strings
@@ -24,9 +25,14 @@
# discs with data tracks. For freedb calculation cd-info is correct, for
# detecting the audio part, cdparanoia is correct.
class ScanDiscCdinfo
+ include AudioCalculations
+
attr_reader :status, :version, :discMode, :deviceName, :totalSectors,
:playtime, :audiotracks, :firstAudioTrack, :dataTracks
-
+
+ # Cd-info starts all tracks with 2 seconds extra if compared with
cdparanoia
+ OFFSET_CDINFO = -150
+
# * cdrom = a string with the location of the drive
# * testRead = a string with output of cd-info for unit testing purposes
def initialize(execute=nil, prefs=nil)
@@ -80,26 +86,6 @@
return @status.nil?
end

- # minutes:seconds:sectors to sectors
- # correct for offset of 150 to match cdparanoia
- def toSectors(time)
- count = -150
- minutes, seconds, sectors = time.split(':')
- count += sectors.to_i
- count += (seconds.to_i * 75)
- count += (minutes.to_i * 60 * 75)
- return count
- end
-
- # now back to time
- def toTime(sectors)
- return '' if sectors == nil
- minutes = sectors / (60*75)
- seconds = ((sectors % (60*75)) / 75)
- frames = sectors - minutes*60*75 - seconds*75
- return "%02d:%02d.%02d" % [minutes, seconds, frames]
- end
-
# store the info of the query in variables
def parseQuery(query)
tracknumber = 0
@@ -114,14 +100,14 @@
if line =~ /\s+\d+:\s/ # for example: ' 1: '
tracknumber = $&.strip()[0..-2].to_i
trackinfo = $'.split(/\s+/)
- @startSector[tracknumber] = toSectors(trackinfo[0])
+ @startSector[tracknumber] = toSectors(trackinfo[0]) + OFFSET_CDINFO
@dataTracks << tracknumber if trackinfo[2] == "data"
@firstAudioTrack = tracknumber unless @firstAudioTrack ||
trackinfo[2] == "data"
end

if line =~ /leadout/
line =~ /\d\d:\d\d:\d\d/
- @totalSectors = toSectors($&)
+ @totalSectors = toSectors($&) + OFFSET_CDINFO
break
end
end
=======================================
--- /lib/rubyripper/disc/scanDiscCdparanoia.rb Wed Jan 2 11:23:31 2013
+++ /lib/rubyripper/disc/scanDiscCdparanoia.rb Wed Jan 9 14:11:49 2013
@@ -19,12 +19,14 @@
require 'rubyripper/disc/permissionDrive'
require 'rubyripper/system/execute'
require 'rubyripper/errors'
+require 'rubyripper/modules/audioCalculations'

# A class that interprets the toc with the info of cdparanoia
# It's purpose is pure for ripping the correct audio, not for
# creating the freedb string. Cd-info is better for that.
# Before ripping, the function checkOffsetFirstTrack should be called.
class ScanDiscCdparanoia
+ include AudioCalculations
include GetText
GetText.bindtextdomain("rubyripper")

@@ -79,7 +81,11 @@
# return the length in bytes, example for track 1 getFileSize(1)
def getFileSize(track=nil)
assertDiscFound('getFileSize')
- track.nil? ? (44 + @totalSectors * 2352) : (44 + @lengthSector[track]
* 2352 if @lengthSector.key?(track))
+ if track.nil?
+ BYTES_WAV_CONTAINER + @totalSectors * BYTES_AUDIO_FRAME
+ elsif @lengthSector.key?(track)
+ BYTES_WAV_CONTAINER + @lengthSector[track] * BYTES_AUDIO_FRAME
+ end
end

def tracks ; return @audiotracks ; end
=======================================
--- /lib/rubyripper/disc/scanDiscCdrdao.rb Wed Jan 2 11:23:31 2013
+++ /lib/rubyripper/disc/scanDiscCdrdao.rb Wed Jan 9 14:11:49 2013
@@ -31,8 +31,10 @@
require 'rubyripper/system/execute'
require 'rubyripper/system/fileAndDir'
require 'rubyripper/errors'
+require 'rubyripper/modules/audioCalculations'

class ScanDiscCdrdao
+ include AudioCalculations
include GetText
GetText.bindtextdomain("rubyripper")

@@ -173,16 +175,6 @@
@log << _("...please be patient, this may take a while\n\n")
end

- # minutes:seconds:sectors to sectors
- def toSectors(time)
- count = 0
- minutes, seconds, sectors = time.split(':')
- count += sectors.to_i
- count += (seconds.to_i * 75)
- count += (minutes.to_i * 60 * 75)
- return count
- end
-
def displayScanResults
if not @error.nil?
@log << @error
=======================================
--- /lib/rubyripper/log.rb Sat Jan 5 13:43:29 2013
+++ /lib/rubyripper/log.rb Wed Jan 9 14:11:49 2013
@@ -16,20 +16,21 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>

require 'rubyripper/preferences/main'
+require 'rubyripper/modules/audiocalculations'
+
# The Log class is responsible for
# * updating the log files
# * keeping track of the reading trials
# * passing update messages to the user interface

class Log
+ include AudioCalculations
include GetText
GetText.bindtextdomain("rubyripper")

attr_reader :rippingErrors, :encodingErrors, :short_summary
attr_writer :encodingErrors

- BYTES_AUDIO_SECTOR = 2352 # conform cdparanoia
-
def initialize(disc, fileScheme, userInterface, updatePercForEachTrack,
prefs=nil, fileAndDir=nil)
@prefs = prefs ? prefs : Preferences::Main.instance
@file = fileAndDir ? fileAndDir : FileAndDir.instance
@@ -108,38 +109,27 @@

# Format a list of bad sectors in a rip.
def listBadSectors(message, errors)
- add(" #{message}\n")
-
+ add(" #{message}\n")
sequential = false
lastSector = false
- errors.each_pair do |k,v|
- # TODO: Is this right? Calculate min/sec/frm Spin into own
function.
- if lastSector != k / BYTES_AUDIO_SECTOR - 1
- if sequential
- # Print the last sector in the last sequence of bad sectors
- min = lastSector / 75 / 60
- sec = lastSector / 75 % 60
- frm = lastSector % 75
- add("%02d:%02d.%02d" % [min, sec, frm])
- end
+
+ errors.each_pair do |key, value|
+ # TODO: Is this right?
+ if lastSector != key / BYTES_AUDIO_FRAME - 1

+ # Print the last sector in the last sequence of bad sectors
+ add(toTime(lastSector)) if sequential
# New sequence starts.
- if lastSector != false
- add("\n")
- end
-
- min = k / BYTES_AUDIO_SECTOR / 75 / 60
- sec = k / BYTES_AUDIO_SECTOR / 75 % 60
- frm = k / BYTES_AUDIO_SECTOR % 75
- add(" %02d:%02d.%02d" % [min, sec, frm])
+ add("\n") if lastSector != false
+ add(toTime(key))

sequential = false
- elsif lastSector == k / BYTES_AUDIO_SECTOR - 1 and !sequential
+ elsif lastSector == key / BYTES_AUDIO_FRAME - 1 and !sequential
# In an actual sequence, rather than a one-off
add("-")
sequential = true
end
- lastSector = k / BYTES_AUDIO_SECTOR
+ lastSector = key / BYTES_AUDIO_FRAME
end
add("\n")
end
@@ -148,7 +138,7 @@
if !@problem_tracks.key?(track) #First time we encounter this track
(Secure_rip->analyzeFiles() )
@problem_tracks[track] = Hash.new # create the Hash for the track
indexes_with_errors.each do |index_of_chunk|
- seconds = index_of_chunk / 176400 # position of chunk rounded in
seconds, each second = 176400 bytes
+ seconds = index_of_chunk / BYTES_AUDIO_SECOND
if !@problem_tracks[track].key?(seconds)
@problem_tracks[track][seconds] = [1, trial] # different_chunks,
trial. First time we encounter this position, so different_chunks = 1
else
@@ -157,7 +147,7 @@
end
else
indexes_with_errors.each do |index_of_chunk|
- seconds = index_of_chunk / 176400 # position of chunk rounded in
seconds, each second = 176400 bytes
+ seconds = index_of_chunk / BYTES_AUDIO_SECOND # position of chunk
rounded in seconds, each second = 176400 bytes
@problem_tracks[track][seconds][1] = trial #Update the amount of
trials needed
end
end
=======================================
--- /lib/rubyripper/rippingInfoAtStart.rb Thu Dec 27 12:29:25 2012
+++ /lib/rubyripper/rippingInfoAtStart.rb Wed Jan 9 14:11:49 2013
@@ -16,9 +16,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>

require 'rubyripper/preferences/main'
-require 'rubyripper/system/execute.rb'
+require 'rubyripper/system/execute'
+require 'rubyripper/modules/audioCalculations'

class RippingInfoAtStart
+ include AudioCalculations
include GetText
GetText.bindtextdomain("rubyripper")

@@ -102,17 +104,10 @@

(1..@disc.audiotracks).each do |track|
# TODO: Needs start sector of data tracks too.
- start = @disc.getStartSector(track)
- start_min = start / 75 / 60
- start_sec = start / 75 % 60
- start_frm = start % 60
-
+ start = @disc.getStartSector(track)
length = @disc.getLengthSector(track)
- length_min = length / 75 / 60
- length_sec = length / 75 % 60
- length_frm = length % 60

- @logString << " %2d | %2d:%02d.%02d | %2d:%02d.%02d
| %6d | %6d \n" % [track, start_min, start_sec, start_frm,
length_min, length_sec, length_frm, start, start + length - 1]
+ @logString << " %2d | %s | %s | %6d | %6d \n" %
[track, toTime(start), toTime(length), start, start + length - 1]
end
@logString << "\n"
end
=======================================
--- /lib/rubyripper/secureRip.rb Wed Jan 2 10:37:39 2013
+++ /lib/rubyripper/secureRip.rb Wed Jan 9 14:11:49 2013
@@ -21,6 +21,7 @@
require 'rubyripper/system/dependency'
require 'rubyripper/system/execute'
require 'rubyripper/preferences/main'
+require 'rubyripper/modules/audioCalculations'

# The SecureRip class is mainly responsible for:
# * Managing cdparanoia to fetch the files
@@ -28,14 +29,12 @@
# * Repairing the files if necessary

class SecureRip
+ include AudioCalculations
include GetText
GetText.bindtextdomain("rubyripper")

attr_writer :cancelled

- BYTES_WAV_CONTAINER = 44 # to store the type of wav file
- BYTES_AUDIO_SECTOR = 2352 # conform cdparanoia
-
def initialize(trackSelection, disc, fileScheme, log, encoding,
deps=nil, exec=nil, prefs=nil)
@prefs = prefs ? prefs : Preferences::Main.instance
@trackSelection = trackSelection
@@ -199,10 +198,10 @@
if sizeDiff == 0
# expected size matches exactly
elsif sizeDiff < 0
- puts "DEBUG: More sectors ripped than expected: #{sizeDiff /
BYTES_AUDIO_SECTOR} sector(s)" if @prefs.debug
+ puts "DEBUG: More sectors ripped than expected: #{sizeDiff /
BYTES_AUDIO_FRAME} sector(s)" if @prefs.debug
elsif @prefs.offset != 0 && (@prefs.image || track ==
@disc.audiotracks)
# This should no longer happen.
- puts "DEBUG: The ripped file misses %s sectors." % [sizeDiff /
BYTES_AUDIO_SECTOR.to_f] if @prefs.debug
+ puts "DEBUG: The ripped file misses %s sectors." % [sizeDiff /
BYTES_AUDIO_FRAME.to_f] if @prefs.debug
elsif @cancelled == false
if @prefs.debug
puts "DEBUG: Some sectors are missing for track #{track} :
#{sizeDiff} sector(s)"
@@ -274,9 +273,9 @@
if sectorEqual?(files[0], files[trial]) && !@errors.key?(index)
setFileIndex(files, index) # set back to read again
@errors[index] = Array.new
- files.each{|file| @errors[index] <<
file.sysread(BYTES_AUDIO_SECTOR)}
+ files.each{|file| @errors[index] <<
file.sysread(BYTES_AUDIO_FRAME)}
end
- index += BYTES_AUDIO_SECTOR
+ index += BYTES_AUDIO_FRAME
end
end

@@ -288,20 +287,18 @@
end

def sectorEqual?(file1, file2)
- file1.sysread(BYTES_AUDIO_SECTOR) == file2.sysread(BYTES_AUDIO_SECTOR)
+ file1.sysread(BYTES_AUDIO_FRAME) == file2.sysread(BYTES_AUDIO_FRAME)
end

# When required matches for mismatched sectors are bigger than there are
# trials to be tested, readErrorPos() just reads the mismatched sectors
# without analysing them.
- # Wav-containter overhead = 44 bytes.
- # Audio-cd sector = 2352 bytes.

def readErrorPos(track=nil)
file = File.new(@fileScheme.getTempFile(track, @trial), 'r')
@errors.keys.sort.each do |start_chunk|
file.pos = start_chunk + BYTES_WAV_CONTAINER
- @errors[start_chunk] << file.sysread(BYTES_AUDIO_SECTOR)
+ @errors[start_chunk] << file.sysread(BYTES_AUDIO_FRAME)
end
file.close

=======================================
--- /lib/rubyripper/system/fileHash.rb Sun Nov 4 06:35:43 2012
+++ /lib/rubyripper/system/fileHash.rb Wed Jan 9 14:11:49 2013
@@ -19,10 +19,10 @@
require 'digest/md5'
# for CRC32 calculation
require 'zlib'
+require 'rubyripper/modules/audioCalculations'

class FileHash
-
- BYTES_WAV_CONTAINER = 44 # to store the type of wav file
+ include AudioCalculations

def initialize(filename, prefs=nil)
@filename = filename
=======================================
--- /lib/rubyripper/waveFile.rb Mon Nov 7 23:31:13 2011
+++ /lib/rubyripper/waveFile.rb Wed Jan 9 14:11:49 2013
@@ -38,14 +38,14 @@

require 'tempfile'
require 'fileutils'
+require 'rubyripper/modules/audioCalculations'

class WaveFile
+ include AudioCalculations
+
attr_reader :path, :offset, :padMissingSamples
attr_writer :offset, :padMissingSamples

- BYTES_WAV_CONTAINER = 44 # size of the wave header from cdparanoia
- BYTES_AUDIO_SECTOR = 2352 # size of a sector in bytes
-
def initialize(path, offset=0, padMissingSamples=false)
@path = path
@newSectors = {}
@@ -56,7 +56,7 @@

# Read a CD-audio sector (padding with 0's, regardless of
padMissingSamples)
def read(sector)
- start = BYTES_WAV_CONTAINER + sector * BYTES_AUDIO_SECTOR + @offset * 4
+ start = BYTES_WAV_CONTAINER + sector * BYTES_AUDIO_FRAME + @offset * 4

if @newSectors.has_key?(sector)
@newSectors[sector]
@@ -66,23 +66,23 @@
if start < BYTES_WAV_CONTAINER and @offset < 0
# Pad the start.
data += "\x00" * [(BYTES_WAV_CONTAINER - start),
- BYTES_AUDIO_SECTOR].min
+ BYTES_AUDIO_FRAME].min
start = BYTES_WAV_CONTAINER
end

- if data.length == BYTES_AUDIO_SECTOR
+ if data.length == BYTES_AUDIO_FRAME
# We're before the start of the file, and only have padding!
data
- elsif data.length < BYTES_AUDIO_SECTOR
+ elsif data.length < BYTES_AUDIO_FRAME
@file.seek(start, IO::SEEK_SET)
- buffer = @file.read(BYTES_AUDIO_SECTOR - data.length)
+ buffer = @file.read(BYTES_AUDIO_FRAME - data.length)
if !buffer.nil?
data += buffer
end

- if data.length < BYTES_AUDIO_SECTOR
+ if data.length < BYTES_AUDIO_FRAME
# Pad the end.
- data += "\x00" * (BYTES_AUDIO_SECTOR - data.length)
+ data += "\x00" * (BYTES_AUDIO_FRAME - data.length)
end

data
@@ -101,7 +101,7 @@

def numSectors
audioSize = @file.stat.size - BYTES_WAV_CONTAINER
- audioSize / BYTES_AUDIO_SECTOR + ((audioSize % BYTES_AUDIO_SECTOR >
0) ? 1 : 0)
+ audioSize / BYTES_AUDIO_FRAME + ((audioSize % BYTES_AUDIO_FRAME > 0) ?
1 : 0)
end

# Set the contents of the sector to (the raw sample data in) other.
@@ -110,7 +110,7 @@
# of sector number [sector] in this with the contents of sector
# number [sector] in (the WaveFile) that.
def splice(sector, data)
- if sector >= 0 and sector < numSectors and data.length ==
BYTES_AUDIO_SECTOR
+ if sector >= 0 and sector < numSectors and data.length ==
BYTES_AUDIO_FRAME
@newSectors[sector] = data
end
end
@@ -121,7 +121,7 @@

# Do we pad the missing samples?
if @padMissingSamples
- audioSize = numSectors * BYTES_AUDIO_SECTOR
+ audioSize = numSectors * BYTES_AUDIO_FRAME
else
audioSize = @file.stat.size - BYTES_WAV_CONTAINER
if @offset != 0
@@ -145,9 +145,9 @@
# Padding is at the end.
bytesWritten = 0
(1..numSectors).each do |sector|
- if bytesWritten + BYTES_AUDIO_SECTOR < audioSize
+ if bytesWritten + BYTES_AUDIO_FRAME < audioSize
f.write(read(sector - 1))
- bytesWritten += BYTES_AUDIO_SECTOR
+ bytesWritten += BYTES_AUDIO_FRAME
elsif bytesWritten < audioSize
f.write(read(sector - 1)[0..(audioSize - bytesWritten - 1)])
bytesWritten = audioSize
@@ -159,15 +159,15 @@
# Padding is at the beginning.
bytesWritten = @offset * 4
(1..numSectors).each do |sector|
- if bytesWritten <= -BYTES_AUDIO_SECTOR
+ if bytesWritten <= -BYTES_AUDIO_FRAME
# Don't bother writing out the sector at all
- bytesWritten += BYTES_AUDIO_SECTOR
+ bytesWritten += BYTES_AUDIO_FRAME
elsif bytesWritten < 0
- f.write(read(sector - 1)[(0 - bytesWritten)..(BYTES_AUDIO_SECTOR
- 1)])
- bytesWritten += BYTES_AUDIO_SECTOR
- elsif bytesWritten + BYTES_AUDIO_SECTOR <= audioSize
+ f.write(read(sector - 1)[(0 - bytesWritten)..(BYTES_AUDIO_FRAME
- 1)])
+ bytesWritten += BYTES_AUDIO_FRAME
+ elsif bytesWritten + BYTES_AUDIO_FRAME <= audioSize
f.write(read(sector - 1))
- bytesWritten += BYTES_AUDIO_SECTOR
+ bytesWritten += BYTES_AUDIO_FRAME
else
break
end
=======================================
--- /spec/disc/scanDiscCdcontrol_spec.rb Mon Oct 31 03:44:52 2011
+++ /spec/disc/scanDiscCdcontrol_spec.rb Wed Jan 9 14:11:49 2013
@@ -86,8 +86,8 @@
setStandardQueryReply()
scan.scan()
scan.getLengthText(14).should == nil
- scan.getLengthText(15).should == '03:21.15'
- scan.getLengthText(16).should == '03:37.45'
+ scan.getLengthText(15).should == '03:21:15'
+ scan.getLengthText(16).should == '03:37:45'
scan.getLengthText(17).should == nil
end

=======================================
--- /spec/disc/scanDiscCdinfo_spec.rb Sun Oct 30 02:37:43 2011
+++ /spec/disc/scanDiscCdinfo_spec.rb Wed Jan 9 14:11:49 2013
@@ -107,8 +107,8 @@
setStandardQueryReply()
scan.scan()
scan.getLengthText(14).should == nil
- scan.getLengthText(15).should == '03:21.15'
- scan.getLengthText(16).should == '03:37.45'
+ scan.getLengthText(15).should == '03:21:15'
+ scan.getLengthText(16).should == '03:37:45'
scan.getLengthText(17).should == nil
end

Reply all
Reply to author
Forward
0 new messages