mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-05-30 15:42:34 +02:00
2017-08-22 Fred Gleason <fredg@paravelsystems.com>
* Implemented SEGUE transitions in rdrender(1).
This commit is contained in:
parent
6659660736
commit
3abb23a77a
@ -15964,3 +15964,5 @@
|
||||
* Added rdrender(1) in 'utils/rdrender/'.
|
||||
2017-08-20 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Removed FIXME entries from 'utils/rdrender/mainloop.cpp'.
|
||||
2017-08-22 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Implemented SEGUE transitions in rdrender(1).
|
||||
|
@ -29,7 +29,8 @@ moc_%.cpp: %.h
|
||||
|
||||
bin_PROGRAMS = rdrender
|
||||
|
||||
dist_rdrender_SOURCES = mainloop.cpp\
|
||||
dist_rdrender_SOURCES = logline.cpp logline.h\
|
||||
mainloop.cpp\
|
||||
rdrender.cpp rdrender.h
|
||||
|
||||
nodist_rdrender_SOURCES = moc_rdrender.cpp
|
||||
|
181
utils/rdrender/logline.cpp
Normal file
181
utils/rdrender/logline.cpp
Normal file
@ -0,0 +1,181 @@
|
||||
// logline.cpp
|
||||
//
|
||||
// Container class for Rivendell Log Line.
|
||||
//
|
||||
// (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 "logline.h"
|
||||
|
||||
#include <rd.h>
|
||||
#include <rdaudioconvert.h>
|
||||
#include <rdaudioexport.h>
|
||||
#include <rdconf.h>
|
||||
|
||||
LogLine::LogLine(RDLogLine *ll,RDUser *user,RDStation *station,RDSystem *sys,
|
||||
RDConfig *config,unsigned chans)
|
||||
: RDLogLine(*ll)
|
||||
{
|
||||
ll_cart=NULL;
|
||||
ll_cut=NULL;
|
||||
ll_handle=NULL;
|
||||
ll_user=user;
|
||||
ll_station=station;
|
||||
ll_system=sys;
|
||||
ll_config=config;
|
||||
ll_channels=chans;
|
||||
ll_ramp_level=0.0;
|
||||
ll_ramp_rate=0.0;
|
||||
}
|
||||
|
||||
|
||||
RDCart *LogLine::cart() const
|
||||
{
|
||||
return ll_cart;
|
||||
}
|
||||
|
||||
|
||||
RDCut *LogLine::cut() const
|
||||
{
|
||||
return ll_cut;
|
||||
}
|
||||
|
||||
|
||||
SNDFILE *LogLine::handle() const
|
||||
{
|
||||
return ll_handle;
|
||||
}
|
||||
|
||||
|
||||
double LogLine::rampLevel() const
|
||||
{
|
||||
return ll_ramp_level;
|
||||
}
|
||||
|
||||
|
||||
void LogLine::setRampLevel(double lvl)
|
||||
{
|
||||
ll_ramp_level=lvl;
|
||||
}
|
||||
|
||||
|
||||
double LogLine::rampRate() const
|
||||
{
|
||||
return ll_ramp_rate;
|
||||
}
|
||||
|
||||
|
||||
void LogLine::setRampRate(double lvl)
|
||||
{
|
||||
ll_ramp_rate=lvl;
|
||||
}
|
||||
|
||||
|
||||
void LogLine::setRamp(RDLogLine::TransType next_trans)
|
||||
{
|
||||
if((next_trans==RDLogLine::Segue)&&
|
||||
(ll_cut->segueStartPoint()>=0)&&(ll_cut->segueEndPoint()>=0)) {
|
||||
ll_ramp_rate=((double)RD_FADE_DEPTH)/((double)FramesFromMsec(ll_cut->segueEndPoint()-ll_cut->segueStartPoint()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool LogLine::open(const QTime &time)
|
||||
{
|
||||
QString cutname;
|
||||
SF_INFO sf_info;
|
||||
|
||||
if(type()==RDLogLine::Cart) {
|
||||
ll_cart=new RDCart(cartNumber());
|
||||
if(ll_cart->exists()&&(ll_cart->type()==RDCart::Audio)) {
|
||||
if(ll_cart->selectCut(&cutname,time)) {
|
||||
ll_cut=new RDCut(cutname);
|
||||
QString filename;
|
||||
if(GetCutFile(cutname,ll_cut->startPoint(),ll_cut->endPoint(),
|
||||
&filename)) {
|
||||
ll_handle=sf_open(filename,SFM_READ,&sf_info);
|
||||
if(ll_handle!=NULL) {
|
||||
DeleteCutFile(filename);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void LogLine::close()
|
||||
{
|
||||
sf_close(ll_handle);
|
||||
ll_handle=NULL;
|
||||
}
|
||||
|
||||
|
||||
bool LogLine::GetCutFile(const QString &cutname,int start_pt,int end_pt,
|
||||
QString *dest_filename) const
|
||||
{
|
||||
bool ret=false;
|
||||
RDAudioConvert::ErrorCode conv_err;
|
||||
RDAudioExport::ErrorCode export_err;
|
||||
char tempdir[PATH_MAX];
|
||||
|
||||
strncpy(tempdir,RDTempDir()+"/rdrenderXXXXXX",PATH_MAX);
|
||||
*dest_filename=QString(mkdtemp(tempdir))+"/"+cutname+".wav";
|
||||
RDAudioExport *conv=new RDAudioExport(ll_station,ll_config);
|
||||
conv->setDestinationFile(*dest_filename);
|
||||
conv->setCartNumber(RDCut::cartNumber(cutname));
|
||||
conv->setCutNumber(RDCut::cutNumber(cutname));
|
||||
RDSettings s;
|
||||
s.setFormat(RDSettings::Pcm16);
|
||||
s.setSampleRate(ll_system->sampleRate());
|
||||
s.setChannels(ll_channels);
|
||||
s.setNormalizationLevel(0);
|
||||
conv->setDestinationSettings(&s);
|
||||
conv->setRange(start_pt,end_pt);
|
||||
conv->setEnableMetadata(false);
|
||||
switch(export_err=conv->runExport(ll_user->name(),
|
||||
ll_user->password(),&conv_err)) {
|
||||
case RDAudioExport::ErrorOk:
|
||||
ret=true;
|
||||
break;
|
||||
|
||||
default:
|
||||
ret=false;
|
||||
printf("export err %d [%s]\n",export_err,
|
||||
(const char *)RDAudioExport::errorText(export_err,conv_err));
|
||||
break;
|
||||
}
|
||||
|
||||
delete conv;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void LogLine::DeleteCutFile(const QString &dest_filename) const
|
||||
{
|
||||
unlink(dest_filename);
|
||||
QStringList f0=f0.split("/",dest_filename);
|
||||
f0.erase(f0.fromLast());
|
||||
rmdir("/"+f0.join("/"));
|
||||
}
|
||||
|
||||
|
||||
uint64_t LogLine::FramesFromMsec(uint64_t msec)
|
||||
{
|
||||
return msec*ll_system->sampleRate()/1000;
|
||||
}
|
70
utils/rdrender/logline.h
Normal file
70
utils/rdrender/logline.h
Normal file
@ -0,0 +1,70 @@
|
||||
// logline.h
|
||||
//
|
||||
// Container class for Rivendell Log Line.
|
||||
//
|
||||
// (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.
|
||||
//
|
||||
|
||||
#ifndef LOGLINE_H
|
||||
#define LOGLINE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include <rdcart.h>
|
||||
#include <rdconfig.h>
|
||||
#include <rdcut.h>
|
||||
#include <rdlog_line.h>
|
||||
#include <rdstation.h>
|
||||
#include <rdsystem.h>
|
||||
|
||||
class LogLine : public RDLogLine
|
||||
{
|
||||
public:
|
||||
LogLine(RDLogLine *ll,RDUser *user,RDStation *station,RDSystem *sys,
|
||||
RDConfig *config,unsigned chans);
|
||||
RDCart *cart() const;
|
||||
RDCut *cut() const;
|
||||
SNDFILE *handle() const;
|
||||
double rampLevel() const;
|
||||
void setRampLevel(double lvl);
|
||||
double rampRate() const;
|
||||
void setRampRate(double lvl);
|
||||
void setRamp(RDLogLine::TransType next_trans);
|
||||
bool open(const QTime &time);
|
||||
void close();
|
||||
|
||||
private:
|
||||
bool GetCutFile(const QString &cutname,int start_pt,int end_pt,
|
||||
QString *dest_filename) const;
|
||||
void DeleteCutFile(const QString &dest_filename) const;
|
||||
uint64_t FramesFromMsec(uint64_t msec);
|
||||
RDCart *ll_cart;
|
||||
RDCut *ll_cut;
|
||||
SNDFILE *ll_handle;
|
||||
RDLogLine *ll_logline;
|
||||
RDUser *ll_user;
|
||||
RDStation *ll_station;
|
||||
RDSystem *ll_system;
|
||||
RDConfig *ll_config;
|
||||
unsigned ll_channels;
|
||||
double ll_ramp_level;
|
||||
double ll_ramp_rate;
|
||||
};
|
||||
|
||||
|
||||
#endif // LOGLINE_H
|
@ -18,9 +18,10 @@
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <sndfile.h>
|
||||
#include <vector>
|
||||
|
||||
#include <rdcart.h>
|
||||
#include <rdcut.h>
|
||||
@ -32,7 +33,7 @@
|
||||
|
||||
int MainObject::MainLoop()
|
||||
{
|
||||
static float pcm[16384];
|
||||
float *pcm=NULL;
|
||||
QTime current_time=render_start_time;
|
||||
// QDate current_date=render_start_date;
|
||||
|
||||
@ -60,34 +61,60 @@ int MainObject::MainLoop()
|
||||
}
|
||||
|
||||
//
|
||||
// Iterate through the log
|
||||
// Initialize the log
|
||||
//
|
||||
std::vector<LogLine *> lls;
|
||||
for(int i=0;i<log_event->size();i++) {
|
||||
RDLogLine *ll=log_event->logLine(i);
|
||||
if(ll->type()==RDLogLine::Cart) {
|
||||
RDCart *cart=new RDCart(ll->cartNumber());
|
||||
if(cart->exists()&&(cart->type()==RDCart::Audio)) {
|
||||
QString cutname;
|
||||
if(cart->selectCut(&cutname,current_time)) {
|
||||
RDCut *cut=new RDCut(cutname);
|
||||
QString filename;
|
||||
if(GetCutFile(cutname,cut->startPoint(),cut->endPoint(),&filename)) {
|
||||
SNDFILE *sf_in=sf_open(filename,SFM_READ,&sf_info);
|
||||
int n;
|
||||
if(sf_in!=NULL) {
|
||||
DeleteCutFile(filename);
|
||||
while((n=sf_readf_float(sf_in,pcm,8192))>0) {
|
||||
sf_writef_float(sf_out,pcm,n);
|
||||
}
|
||||
sf_close(sf_in);
|
||||
}
|
||||
}
|
||||
delete cut;
|
||||
}
|
||||
lls.push_back(new LogLine(log_event->logLine(i),render_user,render_station,
|
||||
render_system,render_config,render_channels));
|
||||
}
|
||||
lls.push_back(new LogLine(new RDLogLine(),render_user,render_station,
|
||||
render_system,render_config,render_channels));
|
||||
lls.back()->setTransType(RDLogLine::Play);
|
||||
|
||||
//
|
||||
// Iterate through it
|
||||
//
|
||||
for(unsigned i=0;i<lls.size();i++) {
|
||||
if((lls.at(i)->transType()==RDLogLine::Stop)&&
|
||||
(lls.at(i)->timeType()!=RDLogLine::Hard)) {
|
||||
Verbose(current_time,i,QString().sprintf("Unconditional STOP on %06u [",
|
||||
lls.at(i)->cartNumber())+
|
||||
lls.at(i)->title()+"]");
|
||||
break;
|
||||
}
|
||||
if(lls.at(i)->open(current_time)) {
|
||||
Verbose(current_time,i,
|
||||
QString().sprintf("starting cart %06u [",lls.at(i)->cartNumber())+
|
||||
lls.at(i)->title()+"]");
|
||||
sf_count_t frames=0;
|
||||
if((lls.at(i+1)->transType()==RDLogLine::Segue)&&
|
||||
(lls.at(i)->cut()->segueStartPoint()>=0)) {
|
||||
frames=FramesFromMsec(lls.at(i)->cut()->segueStartPoint()-
|
||||
lls.at(i)->cut()->startPoint());
|
||||
current_time=current_time.addMSecs(lls.at(i)->cut()->segueStartPoint()-
|
||||
lls.at(i)->cut()->startPoint());
|
||||
}
|
||||
delete cart;
|
||||
else {
|
||||
frames=FramesFromMsec(lls.at(i)->cut()->endPoint()-
|
||||
lls.at(i)->cut()->startPoint());
|
||||
current_time=current_time.addMSecs(lls.at(i)->cut()->endPoint()-
|
||||
lls.at(i)->cut()->startPoint());
|
||||
}
|
||||
pcm=new float[frames*render_channels];
|
||||
memset(pcm,0,frames*render_channels);
|
||||
|
||||
for(unsigned j=0;j<i;j++) {
|
||||
Sum(pcm,lls.at(j),frames);
|
||||
}
|
||||
Sum(pcm,lls.at(i),frames);
|
||||
sf_writef_float(sf_out,pcm,frames);
|
||||
delete pcm;
|
||||
pcm=NULL;
|
||||
lls.at(i)->setRamp(lls.at(i+1)->transType());
|
||||
}
|
||||
}
|
||||
Verbose(current_time,lls.size()-1,"--- end of log ---");
|
||||
|
||||
//
|
||||
// Clean up
|
||||
@ -95,3 +122,25 @@ int MainObject::MainLoop()
|
||||
sf_close(sf_out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void MainObject::Sum(float *pcm_out,LogLine *ll,sf_count_t frames)
|
||||
{
|
||||
if(ll->handle()!=NULL) {
|
||||
float *pcm=new float[frames*render_channels];
|
||||
|
||||
memset(pcm,0,frames*render_channels);
|
||||
sf_count_t n=sf_readf_float(ll->handle(),pcm,frames);
|
||||
for(sf_count_t i=0;i<n;i+=render_channels) {
|
||||
double ratio=exp10(((double)i*ll->rampRate()+ll->rampLevel())/2000.0);
|
||||
for(sf_count_t j=0;j<render_channels;j++) {
|
||||
pcm_out[i*render_channels+j]+=ratio*pcm[i*render_channels+j];
|
||||
}
|
||||
}
|
||||
ll->setRampLevel((double)n*ll->rampRate()+ll->rampLevel());
|
||||
if(n<frames) {
|
||||
ll->close();
|
||||
}
|
||||
delete pcm;
|
||||
}
|
||||
}
|
||||
|
@ -177,6 +177,12 @@ void MainObject::Verbose(const QString &msg)
|
||||
}
|
||||
|
||||
|
||||
void MainObject::Verbose(const QTime &time,int line,const QString &msg)
|
||||
{
|
||||
Verbose(time.toString("hh:mm:ss.zzz")+QString().sprintf("-%04d : ",line)+msg);
|
||||
}
|
||||
|
||||
|
||||
bool MainObject::GetCutFile(const QString &cutname,int start_pt,int end_pt,
|
||||
QString *dest_filename) const
|
||||
{
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include <qdatetime.h>
|
||||
#include <qobject.h>
|
||||
|
||||
@ -33,6 +35,8 @@
|
||||
#include <rdsystem.h>
|
||||
#include <rduser.h>
|
||||
|
||||
#include "logline.h"
|
||||
|
||||
#define RDRENDER_DEFAULT_CHANNELS 2
|
||||
#define RDRENDER_USAGE "[options] <logname> <output-file>\n"
|
||||
|
||||
@ -47,8 +51,10 @@ class MainObject : public QObject
|
||||
|
||||
private:
|
||||
int MainLoop();
|
||||
void Sum(float *pcm_out,LogLine *ll,sf_count_t frames);
|
||||
uint64_t FramesFromMsec(uint64_t msec);
|
||||
void Verbose(const QString &msg);
|
||||
void Verbose(const QTime &time,int line,const QString &msg);
|
||||
bool GetCutFile(const QString &cutname,int start_pt,int end_pt,
|
||||
QString *dest_filename) const;
|
||||
void DeleteCutFile(const QString &dest_filename) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user