2017-05-26 Fred Gleason <fredg@paravelsystems.com>

* Added rdconvert(1).
This commit is contained in:
Fred Gleason
2017-05-26 08:55:29 -04:00
parent 27075036d1
commit 2c1f1c6a59
14 changed files with 632 additions and 1 deletions

View File

@@ -36,6 +36,7 @@ SUBDIRS = $(ALSACONFIG_RD_OPT)\
rdcleandirs\
rdclilogedit\
rdcollect\
rdconvert\
rddelete\
rddiscimport\
rdexport\

View File

@@ -0,0 +1,50 @@
## automake.am
##
## Automake.am for rivendell/utils/rdconvert
##
## (C) Copyright 2017 Fred Gleason <fredg@paravelsystems.com>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License version 2 as
## published by the Free Software Foundation.
##
## 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, write to the Free Software
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
##
## Use automake to process this into a Makefile.in
AM_CPPFLAGS = -Wall -DPREFIX=\"$(prefix)\" -DQTDIR=\"@QT_DIR@\" @QT_CXXFLAGS@ -I$(top_srcdir)/lib
LIBS = @QT_LIBS@ -L$(top_srcdir)/lib
MOC = @QT_MOC@
# The dependency for qt's Meta Object Compiler (moc)
moc_%.cpp: %.h
$(MOC) $< -o $@
bin_PROGRAMS = rdconvert
dist_rdconvert_SOURCES = rdconvert.cpp rdconvert.h
rdconvert_LDADD = @LIB_RDLIBS@ @LIBVORBIS@
CLEANFILES = *~\
*.exe\
*.idb\
*ilk\
*.obj\
*.pdb\
*.qm\
moc_*
MAINTAINERCLEANFILES = *~\
*.tar.gz\
aclocal.m4\
configure\
Makefile.in\
moc_*

View File

@@ -0,0 +1,209 @@
// rdconvert.cpp
//
// Rivendell file format converter.
//
// (C) Copyright 2017 Fred Gleason <fredg@paravelsystems.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// 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, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include <qapplication.h>
#include <rddb.h>
#include <rdcmd_switch.h>
#include <rdaudioconvert.h>
#include "rdconvert.h"
MainObject::MainObject(QObject *parent)
:QObject(parent)
{
unsigned schema=0;
destination_settings=new RDSettings();
start_point=-1;
end_point=-1;
speed_ratio=1.0;
bool ok=false;
RDAudioConvert::ErrorCode conv_err;
//
// Read Command Options
//
RDCmdSwitch *cmd=
new RDCmdSwitch(qApp->argc(),qApp->argv(),"rdconvert",
RDCONVERT_USAGE);
if(cmd->keys()<1) {
fprintf(stderr,"rdconvert: missing argument\n");
exit(256);
}
source_filename=cmd->key(cmd->keys()-1);
for(unsigned i=0;i<cmd->keys()-1;i++) {
/*
if(cmd->key(i)=="--source-file") {
source_filename=cmd->value(i);
cmd->setProcessed(i,true);
}
*/
if(cmd->key(i)=="--destination-file") {
destination_filename=cmd->value(i);
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--start-point") {
start_point=cmd->value(i).toInt(&ok);
if(!ok) {
fprintf(stderr,"rdconvert: invalid start point\n");
exit(256);
}
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--end-point") {
end_point=cmd->value(i).toInt(&ok);
if(!ok) {
fprintf(stderr,"rdconvert: invalid end point\n");
exit(256);
}
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--destination-format") {
RDSettings::Format format=(RDSettings::Format)cmd->value(i).toInt(&ok);
if(!ok) {
fprintf(stderr,"rdconvert: invalid destination format\n");
exit(256);
}
switch(format) {
case RDSettings::Pcm16:
case RDSettings::Pcm24:
case RDSettings::MpegL2:
case RDSettings::MpegL2Wav:
case RDSettings::MpegL3:
case RDSettings::Flac:
case RDSettings::OggVorbis:
destination_settings->setFormat(format);
cmd->setProcessed(i,true);
break;
default:
fprintf(stderr,"rdconvert: invalid destination format\n");
exit(256);
}
destination_settings->setFormat(format);
}
if(cmd->key(i)=="--destination-channels") {
unsigned channels=cmd->value(i).toInt(&ok);
if(!ok) {
fprintf(stderr,"rdconvert: invalid destination channels\n");
exit(256);
}
destination_settings->setChannels(channels);
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--destination-sample-rate") {
unsigned sample_rate=cmd->value(i).toInt(&ok);
if(!ok) {
fprintf(stderr,"rdconvert: invalid destination sample rate\n");
exit(256);
}
destination_settings->setSampleRate(sample_rate);
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--destination-bit-rate") {
unsigned bit_rate=cmd->value(i).toInt(&ok);
if(!ok) {
fprintf(stderr,"rdconvert: invalid destination bit rate\n");
exit(256);
}
destination_settings->setBitRate(bit_rate);
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--quality") {
unsigned quality=cmd->value(i).toInt(&ok);
if(!ok) {
fprintf(stderr,"rdconvert: invalid destination quality\n");
exit(256);
}
destination_settings->setQuality(quality);
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--normalization-level") {
int normalization_level=cmd->value(i).toInt(&ok);
if((!ok)||(normalization_level>0)) {
fprintf(stderr,"rdconvert: invalid normalization level\n");
exit(256);
}
destination_settings->setNormalizationLevel(normalization_level);
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--speed-ratio") {
speed_ratio=cmd->value(i).toFloat(&ok);
if((!ok)||(speed_ratio<=0)) {
fprintf(stderr,"rdconvert: invalid speed-ratio\n");
exit(256);
}
cmd->setProcessed(i,true);
}
}
if(source_filename.isEmpty()) {
fprintf(stderr,"rdconvert: missing source-file\n");
exit(256);
}
if(destination_filename.isEmpty()) {
destination_filename=source_filename+"."+
RDSettings::defaultExtension(destination_settings->format());
}
if((destination_settings->bitRate()!=0)&&
(destination_settings->quality()!=0)) {
fprintf(stderr,"rdconvert: --destination-bit-rate and --destination-quality are mutually exclusive\n");
exit(256);
}
//
// Read Configuration
//
rdconfig=new RDConfig();
rdconfig->load();
//
// Open Database
//
QString err (tr("rdconvert: "));
QSqlDatabase *db=RDInitDb(&schema,&err);
if(!db) {
fprintf(stderr,err.ascii());
delete cmd;
exit(256);
}
RDAudioConvert *conv=new RDAudioConvert(rdconfig->stationName(),this);
conv->setSourceFile(source_filename);
conv->setDestinationFile(destination_filename);
conv->setDestinationSettings(destination_settings);
conv->setRange(start_point,end_point);
conv->setSpeedRatio(speed_ratio);
conv_err=conv->convert();
if(conv_err!=RDAudioConvert::ErrorOk) {
fprintf(stderr,"%s\n",(const char *)RDAudioConvert::errorText(conv_err));
exit(256);
}
exit(0);
}
int main(int argc,char *argv[])
{
QApplication a(argc,argv,false);
new MainObject();
return a.exec();
}

View File

@@ -0,0 +1,56 @@
// rdconvert.h
//
// Rivendell file format converter.
//
// (C) Copyright 2010-2016 Fred Gleason <fredg@paravelsystems.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// 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, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#ifndef RDCONVERT_H
#define RDCONVERT_H
#include <list>
#include <qobject.h>
#include <qsqldatabase.h>
#include <rdconfig.h>
#include <rdsettings.h>
#include <rdcmd_switch.cpp>
#define RDCONVERT_USAGE "[options] <src-file>\n\nTest the Rivendell audio converter routines\n\nOptions are:\n--destination-file=<filename>\n\n--start-point=<msecs>\n\n--end-point=<msecs>\n\n--destination-format=<fmt>\n Supported formats are:\n 0 - PCM16 WAV\n 2 - MPEG Layer 2\n 3 - MPEG Layer 3\n 4 - FLAC\n 5 - OggVorbis\n 6 - MPEG Layer 2 WAV\n 7 - PCM24 WAV\n\n--destination-channels=<chans>\n\n--destination-sample-rate=<rate>\n\n--destination-bit-rate=<rate>\n\n--destination-quality=<qual>\n\n--normalization-level=<dbfs>\n\n--speed-ratio=<ratio>\n\n"
//
// Global Variables
//
RDConfig *rdconfig;
class MainObject : public QObject
{
public:
MainObject(QObject *parent=0);
private:
QString source_filename;
QString destination_filename;
int start_point;
int end_point;
float speed_ratio;
RDSettings *destination_settings;
};
#endif // RDCONVERT_H