Fix OGG encoder issues
This commit is contained in:
parent
639c372a22
commit
11063b61f2
|
@ -116,6 +116,7 @@ find_package (Threads REQUIRED)
|
||||||
find_package(CppUnit)
|
find_package(CppUnit)
|
||||||
find_package(Doxygen)
|
find_package(Doxygen)
|
||||||
find_package(Volk REQUIRED)
|
find_package(Volk REQUIRED)
|
||||||
|
find_package(OggVorbis REQUIRED)
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
# Include or not into the module blocks for debugging
|
# Include or not into the module blocks for debugging
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
# - Try to find the OggVorbis libraries
|
||||||
|
# Once done this will define
|
||||||
|
#
|
||||||
|
# OGGVORBIS_FOUND - system has OggVorbis
|
||||||
|
# OGGVORBIS_VERSION - set either to 1 or 2
|
||||||
|
# OGG_INCLUDE_DIR - the OggVorbis include directory
|
||||||
|
# VORBIS_INCLUDE_DIR - the OggVorbis include directory
|
||||||
|
# OGGVORBIS_LIBRARIES - The libraries needed to use OggVorbis
|
||||||
|
# OGG_LIBRARY - The Ogg library
|
||||||
|
# VORBIS_LIBRARY - The Vorbis library
|
||||||
|
# VORBISFILE_LIBRARY - The VorbisFile library
|
||||||
|
# VORBISENC_LIBRARY - The VorbisEnc library
|
||||||
|
|
||||||
|
# Copyright (c) 2006, Richard Laerkaeng, <richard@goteborg.utfors.se>
|
||||||
|
#
|
||||||
|
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||||
|
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||||
|
|
||||||
|
|
||||||
|
include (CheckLibraryExists)
|
||||||
|
|
||||||
|
find_path(VORBIS_INCLUDE_DIR vorbis/vorbisfile.h)
|
||||||
|
find_path(OGG_INCLUDE_DIR ogg/ogg.h)
|
||||||
|
|
||||||
|
find_library(OGG_LIBRARY NAMES ogg)
|
||||||
|
find_library(VORBIS_LIBRARY NAMES vorbis)
|
||||||
|
find_library(VORBISFILE_LIBRARY NAMES vorbisfile)
|
||||||
|
find_library(VORBISENC_LIBRARY NAMES vorbisenc)
|
||||||
|
|
||||||
|
|
||||||
|
if (VORBIS_INCLUDE_DIR AND VORBIS_LIBRARY AND VORBISFILE_LIBRARY AND VORBISENC_LIBRARY)
|
||||||
|
set(OGGVORBIS_FOUND TRUE)
|
||||||
|
|
||||||
|
set(OGGVORBIS_LIBRARIES ${OGG_LIBRARY} ${VORBIS_LIBRARY} ${VORBISFILE_LIBRARY} ${VORBISENC_LIBRARY})
|
||||||
|
|
||||||
|
set(_CMAKE_REQUIRED_LIBRARIES_TMP ${CMAKE_REQUIRED_LIBRARIES})
|
||||||
|
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${OGGVORBIS_LIBRARIES})
|
||||||
|
check_library_exists(vorbis vorbis_bitrate_addblock "" HAVE_LIBVORBISENC2)
|
||||||
|
set(CMAKE_REQUIRED_LIBRARIES ${_CMAKE_REQUIRED_LIBRARIES_TMP})
|
||||||
|
|
||||||
|
if (HAVE_LIBVORBISENC2)
|
||||||
|
set (OGGVORBIS_VERSION 2)
|
||||||
|
else (HAVE_LIBVORBISENC2)
|
||||||
|
set (OGGVORBIS_VERSION 1)
|
||||||
|
endif (HAVE_LIBVORBISENC2)
|
||||||
|
|
||||||
|
else (VORBIS_INCLUDE_DIR AND VORBIS_LIBRARY AND VORBISFILE_LIBRARY AND VORBISENC_LIBRARY)
|
||||||
|
set (OGGVORBIS_VERSION)
|
||||||
|
set(OGGVORBIS_FOUND FALSE)
|
||||||
|
endif (VORBIS_INCLUDE_DIR AND VORBIS_LIBRARY AND VORBISFILE_LIBRARY AND VORBISENC_LIBRARY)
|
||||||
|
|
||||||
|
|
||||||
|
if (OGGVORBIS_FOUND)
|
||||||
|
if (NOT OggVorbis_FIND_QUIETLY)
|
||||||
|
message(STATUS "Found OggVorbis: ${OGGVORBIS_LIBRARIES}")
|
||||||
|
endif (NOT OggVorbis_FIND_QUIETLY)
|
||||||
|
else (OGGVORBIS_FOUND)
|
||||||
|
if (OggVorbis_FIND_REQUIRED)
|
||||||
|
message(FATAL_ERROR "Could NOT find OggVorbis libraries")
|
||||||
|
endif (OggVorbis_FIND_REQUIRED)
|
||||||
|
if (NOT OggVorbis_FIND_QUITELY)
|
||||||
|
message(STATUS "Could NOT find OggVorbis libraries")
|
||||||
|
endif (NOT OggVorbis_FIND_QUITELY)
|
||||||
|
endif (OGGVORBIS_FOUND)
|
||||||
|
|
||||||
|
#check_include_files(vorbis/vorbisfile.h HAVE_VORBISFILE_H)
|
||||||
|
#check_library_exists(ogg ogg_page_version "" HAVE_LIBOGG)
|
||||||
|
#check_library_exists(vorbis vorbis_info_init "" HAVE_LIBVORBIS)
|
||||||
|
#check_library_exists(vorbisfile ov_open "" HAVE_LIBVORBISFILE)
|
||||||
|
#check_library_exists(vorbisenc vorbis_info_clear "" HAVE_LIBVORBISENC)
|
||||||
|
#check_library_exists(vorbis vorbis_bitrate_addblock "" HAVE_LIBVORBISENC2)
|
||||||
|
|
||||||
|
#if (HAVE_LIBOGG AND HAVE_VORBISFILE_H AND HAVE_LIBVORBIS AND HAVE_LIBVORBISFILE AND HAVE_LIBVORBISENC)
|
||||||
|
# message(STATUS "Ogg/Vorbis found")
|
||||||
|
# set (VORBIS_LIBS "-lvorbis -logg")
|
||||||
|
# set (VORBISFILE_LIBS "-lvorbisfile")
|
||||||
|
# set (VORBISENC_LIBS "-lvorbisenc")
|
||||||
|
# set (OGGVORBIS_FOUND TRUE)
|
||||||
|
# if (HAVE_LIBVORBISENC2)
|
||||||
|
# set (HAVE_VORBIS 2)
|
||||||
|
# else (HAVE_LIBVORBISENC2)
|
||||||
|
# set (HAVE_VORBIS 1)
|
||||||
|
# endif (HAVE_LIBVORBISENC2)
|
||||||
|
#else (HAVE_LIBOGG AND HAVE_VORBISFILE_H AND HAVE_LIBVORBIS AND HAVE_LIBVORBISFILE AND HAVE_LIBVORBISENC)
|
||||||
|
# message(STATUS "Ogg/Vorbis not found")
|
||||||
|
#endif (HAVE_LIBOGG AND HAVE_VORBISFILE_H AND HAVE_LIBVORBIS AND HAVE_LIBVORBISFILE AND HAVE_LIBVORBISENC)
|
|
@ -31,6 +31,7 @@ list(APPEND enabled_blocks
|
||||||
satnogs_cw_matched_filter_ff.xml
|
satnogs_cw_matched_filter_ff.xml
|
||||||
satnogs_morse_decoder.xml
|
satnogs_morse_decoder.xml
|
||||||
satnogs_multi_format_msg_sink.xml
|
satnogs_multi_format_msg_sink.xml
|
||||||
|
satnogs_ogg_encoder.xml
|
||||||
satnogs_cw_to_symbol.xml
|
satnogs_cw_to_symbol.xml
|
||||||
satnogs_sine_matched_filter_ff.xml
|
satnogs_sine_matched_filter_ff.xml
|
||||||
satnogs_udp_msg_source.xml
|
satnogs_udp_msg_source.xml
|
||||||
|
@ -48,5 +49,5 @@ if(${INCLUDE_DEBUG_BLOCKS})
|
||||||
endif()
|
endif()
|
||||||
install(FILES
|
install(FILES
|
||||||
${enabled_blocks}
|
${enabled_blocks}
|
||||||
satnogs_ogg_enc.xml DESTINATION share/gnuradio/grc/blocks
|
DESTINATION share/gnuradio/grc/blocks
|
||||||
)
|
)
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
<block>satnogs_cw_matched_filter_ff</block>
|
<block>satnogs_cw_matched_filter_ff</block>
|
||||||
<block>satnogs_morse_decoder</block>
|
<block>satnogs_morse_decoder</block>
|
||||||
<block>satnogs_multi_format_msg_sink</block>
|
<block>satnogs_multi_format_msg_sink</block>
|
||||||
|
<block>satnogs_ogg_encoder</block>
|
||||||
<block>satnogs_cw_to_symbol</block>
|
<block>satnogs_cw_to_symbol</block>
|
||||||
<block>satnogs_sine_matched_filter_ff</block>
|
<block>satnogs_sine_matched_filter_ff</block>
|
||||||
<block>satnogs_udp_msg_source</block>
|
<block>satnogs_udp_msg_source</block>
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
<?xml version="1.0"?>
|
|
||||||
<block>
|
|
||||||
<name>ogg_enc</name>
|
|
||||||
<key>satnogs_ogg_enc</key>
|
|
||||||
<category>[satnogs]</category>
|
|
||||||
<import>import satnogs</import>
|
|
||||||
<make>satnogs.ogg_enc($filename, $samp_rate, $quality)</make>
|
|
||||||
<!-- Make one 'param' node for every Parameter you want settable from the GUI.
|
|
||||||
Sub-nodes:
|
|
||||||
* name
|
|
||||||
* key (makes the value accessible as $keyname, e.g. in the make node)
|
|
||||||
* type -->
|
|
||||||
<param>
|
|
||||||
<name>...</name>
|
|
||||||
<key>...</key>
|
|
||||||
<type>...</type>
|
|
||||||
</param>
|
|
||||||
|
|
||||||
<!-- Make one 'sink' node per input. Sub-nodes:
|
|
||||||
* name (an identifier for the GUI)
|
|
||||||
* type
|
|
||||||
* vlen
|
|
||||||
* optional (set to 1 for optional inputs) -->
|
|
||||||
<sink>
|
|
||||||
<name>in</name>
|
|
||||||
<type><!-- e.g. int, float, complex, byte, short, xxx_vector, ...--></type>
|
|
||||||
</sink>
|
|
||||||
|
|
||||||
<!-- Make one 'source' node per output. Sub-nodes:
|
|
||||||
* name (an identifier for the GUI)
|
|
||||||
* type
|
|
||||||
* vlen
|
|
||||||
* optional (set to 1 for optional inputs) -->
|
|
||||||
<source>
|
|
||||||
<name>out</name>
|
|
||||||
<type><!-- e.g. int, float, complex, byte, short, xxx_vector, ...--></type>
|
|
||||||
</source>
|
|
||||||
</block>
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<block>
|
||||||
|
<name>OGG Encoder</name>
|
||||||
|
<key>satnogs_ogg_encoder</key>
|
||||||
|
<import>import satnogs</import>
|
||||||
|
<make>satnogs.ogg_encoder($filename, $samp_rate, $quality)</make>
|
||||||
|
|
||||||
|
<param>
|
||||||
|
<name>File</name>
|
||||||
|
<key>filename</key>
|
||||||
|
<value></value>
|
||||||
|
<type>file_save</type>
|
||||||
|
</param>
|
||||||
|
|
||||||
|
<param>
|
||||||
|
<name>Sampling rate</name>
|
||||||
|
<key>samp_rate</key>
|
||||||
|
<type>real</type>
|
||||||
|
</param>
|
||||||
|
|
||||||
|
<param>
|
||||||
|
<name>Quality</name>
|
||||||
|
<key>quality</key>
|
||||||
|
<value>0.8</value>
|
||||||
|
<type>real</type>
|
||||||
|
</param>
|
||||||
|
|
||||||
|
<sink>
|
||||||
|
<name>in</name>
|
||||||
|
<type>float</type>
|
||||||
|
</sink>
|
||||||
|
</block>
|
|
@ -37,6 +37,7 @@ list(APPEND HEADER_FILES
|
||||||
morse.h
|
morse.h
|
||||||
morse_decoder.h
|
morse_decoder.h
|
||||||
multi_format_msg_sink.h
|
multi_format_msg_sink.h
|
||||||
|
ogg_encoder.h
|
||||||
cw_to_symbol.h
|
cw_to_symbol.h
|
||||||
sine_matched_filter_ff.h
|
sine_matched_filter_ff.h
|
||||||
utils.h
|
utils.h
|
||||||
|
@ -61,6 +62,6 @@ if(${INCLUDE_DEBUG_BLOCKS})
|
||||||
list(APPEND HEADER_FILES ${DEBUG_HEADER_FILES})
|
list(APPEND HEADER_FILES ${DEBUG_HEADER_FILES})
|
||||||
endif()
|
endif()
|
||||||
install(FILES
|
install(FILES
|
||||||
${HEADER_FILES}
|
${HEADER_FILES}
|
||||||
ogg_enc.h DESTINATION include/satnogs
|
DESTINATION include/satnogs
|
||||||
)
|
)
|
|
@ -24,28 +24,29 @@
|
||||||
#include <satnogs/api.h>
|
#include <satnogs/api.h>
|
||||||
#include <gnuradio/sync_block.h>
|
#include <gnuradio/sync_block.h>
|
||||||
|
|
||||||
namespace gr {
|
namespace gr
|
||||||
namespace satnogs {
|
{
|
||||||
|
namespace satnogs
|
||||||
|
{
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief <+description of block+>
|
* \brief Ogg encoder and sink block
|
||||||
* \ingroup satnogs
|
* \ingroup satnogs
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class SATNOGS_API ogg_encoder : virtual public gr::sync_block
|
class SATNOGS_API ogg_encoder : virtual public gr::sync_block
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef boost::shared_ptr<ogg_encoder> sptr;
|
typedef boost::shared_ptr<ogg_encoder> sptr;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Return a shared_ptr to a new instance of satnogs::ogg_encoder.
|
* Ogg encoder and sink block.
|
||||||
*
|
* @param filename filename of the output file
|
||||||
* To avoid accidental use of raw pointers, satnogs::ogg_encoder's
|
* @param samp_rate the sampling rate
|
||||||
* constructor is in a private implementation
|
* @param quality the quality of the output file. [0.1 - 1.0] (worst - best)
|
||||||
* class. satnogs::ogg_encoder::make is the public interface for
|
|
||||||
* creating new instances.
|
|
||||||
*/
|
*/
|
||||||
static sptr make(char* filename, double samp_rate, float quality);
|
static sptr
|
||||||
|
make (char* filename, double samp_rate, float quality);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace satnogs
|
} // namespace satnogs
|
|
@ -25,7 +25,8 @@ include(GrPlatform) #define LIB_SUFFIX
|
||||||
include_directories(
|
include_directories(
|
||||||
${Boost_INCLUDE_DIR}
|
${Boost_INCLUDE_DIR}
|
||||||
${VOLK_INCLUDE_DIRS}
|
${VOLK_INCLUDE_DIRS}
|
||||||
${OGG_INCLUDE_DIRS}
|
${VORBIS_INCLUDE_DIR}
|
||||||
|
${OGG_INCLUDE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
link_directories(${Boost_LIBRARY_DIRS})
|
link_directories(${Boost_LIBRARY_DIRS})
|
||||||
|
@ -41,6 +42,7 @@ list(APPEND satnogs_sources
|
||||||
morse_tree.cc
|
morse_tree.cc
|
||||||
morse_decoder_impl.cc
|
morse_decoder_impl.cc
|
||||||
multi_format_msg_sink_impl.cc
|
multi_format_msg_sink_impl.cc
|
||||||
|
ogg_encoder_impl.cc
|
||||||
cw_to_symbol_impl.cc
|
cw_to_symbol_impl.cc
|
||||||
sine_matched_filter_ff_impl.cc
|
sine_matched_filter_ff_impl.cc
|
||||||
udp_msg_source_impl.cc
|
udp_msg_source_impl.cc
|
||||||
|
@ -57,8 +59,7 @@ list(APPEND satnogs_sources
|
||||||
ax25_encoder_mb_impl.cc
|
ax25_encoder_mb_impl.cc
|
||||||
ax25_decoder_bm_impl.cc
|
ax25_decoder_bm_impl.cc
|
||||||
qb50_deframer_impl.cc
|
qb50_deframer_impl.cc
|
||||||
waterfall_sink_impl.cc
|
waterfall_sink_impl.cc)
|
||||||
ogg_enc_impl.cc )
|
|
||||||
|
|
||||||
if(${INCLUDE_DEBUG_BLOCKS})
|
if(${INCLUDE_DEBUG_BLOCKS})
|
||||||
list(APPEND satnogs_sources ${satnogs_debug_sources})
|
list(APPEND satnogs_sources ${satnogs_debug_sources})
|
||||||
|
@ -78,9 +79,7 @@ target_link_libraries(gnuradio-satnogs
|
||||||
${CMAKE_THREAD_LIBS_INIT}
|
${CMAKE_THREAD_LIBS_INIT}
|
||||||
${NOVA_LIBRARIES}
|
${NOVA_LIBRARIES}
|
||||||
${VOLK_LIBRARIES}
|
${VOLK_LIBRARIES}
|
||||||
ogg
|
${OGGVORBIS_LIBRARIES}
|
||||||
vorbis
|
|
||||||
vorbisenc
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(gnuradio-satnogs PROPERTIES DEFINE_SYMBOL "gnuradio_satnogs_EXPORTS")
|
set_target_properties(gnuradio-satnogs PROPERTIES DEFINE_SYMBOL "gnuradio_satnogs_EXPORTS")
|
||||||
|
|
|
@ -1,135 +0,0 @@
|
||||||
/* -*- c++ -*- */
|
|
||||||
/*
|
|
||||||
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
|
|
||||||
*
|
|
||||||
* Copyright (C) 2017, Libre Space Foundation <http://librespacefoundation.org/>
|
|
||||||
*
|
|
||||||
* This program 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include "config.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <gnuradio/io_signature.h>
|
|
||||||
#include "ogg_encoder_impl.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace gr {
|
|
||||||
namespace satnogs {
|
|
||||||
|
|
||||||
ogg_encoder::sptr
|
|
||||||
ogg_encoder::make(char* filename, double samp_rate, float quality)
|
|
||||||
{
|
|
||||||
return gnuradio::get_initial_sptr
|
|
||||||
(new ogg_encoder_impl(filename, samp_rate, quality));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The private constructor
|
|
||||||
*/
|
|
||||||
ogg_encoder_impl::ogg_encoder_impl(char* filename, double samp_rate, float quality)
|
|
||||||
: gr::sync_block("ogg_encoder",
|
|
||||||
gr::io_signature::make(1, 1, sizeof(float)),
|
|
||||||
gr::io_signature::make(0, 0, 0))
|
|
||||||
{
|
|
||||||
d_quality = quality;
|
|
||||||
d_out=fopen(filename,"wb");
|
|
||||||
d_samp_rate = samp_rate;
|
|
||||||
vorbis_info_init(&d_vi);
|
|
||||||
int ret = vorbis_encode_init_vbr(&d_vi,1,d_samp_rate,d_quality);
|
|
||||||
if(ret)exit(1);
|
|
||||||
|
|
||||||
vorbis_comment_init(&d_vc);
|
|
||||||
vorbis_comment_add_tag(&d_vc, "ENCODER", "satnogs ogg encoder");
|
|
||||||
|
|
||||||
vorbis_analysis_init(&d_vd, &d_vi);
|
|
||||||
vorbis_block_init(&d_vd, &d_vb);
|
|
||||||
|
|
||||||
srand(time(NULL));
|
|
||||||
ogg_stream_init(&d_os, rand());
|
|
||||||
|
|
||||||
ogg_packet header;
|
|
||||||
ogg_packet header_comm;
|
|
||||||
ogg_packet header_code;
|
|
||||||
|
|
||||||
vorbis_analysis_headerout(&d_vd, &d_vc, &header, &header_comm, &header_code);
|
|
||||||
ogg_stream_packetin(&d_os, &header);
|
|
||||||
ogg_stream_packetin(&d_os, &header_comm);
|
|
||||||
ogg_stream_packetin(&d_os, &header_code);
|
|
||||||
int result = 1;
|
|
||||||
while(result){
|
|
||||||
result=ogg_stream_flush(&d_os,&d_og);
|
|
||||||
if(result==0)break;
|
|
||||||
fwrite(d_og.header,1,d_og.header_len,d_out);
|
|
||||||
fwrite(d_og.body,1,d_og.body_len,d_out);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ogg_encoder_impl::~ogg_encoder_impl()
|
|
||||||
{
|
|
||||||
vorbis_analysis_wrote(&d_vd,0);
|
|
||||||
ogg_stream_clear(&d_os);
|
|
||||||
vorbis_block_clear(&d_vb);
|
|
||||||
vorbis_dsp_clear(&d_vd);
|
|
||||||
vorbis_comment_clear(&d_vc);
|
|
||||||
vorbis_info_clear(&d_vi);
|
|
||||||
fclose(d_out);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
ogg_encoder_impl::work(int noutput_items,
|
|
||||||
gr_vector_const_void_star &input_items,
|
|
||||||
gr_vector_void_star &output_items)
|
|
||||||
{
|
|
||||||
size_t chunks = (noutput_items*sizeof(float))/2;
|
|
||||||
const signed char *in = (const signed char *) input_items[0];
|
|
||||||
int i;
|
|
||||||
long bytes = 1024;
|
|
||||||
float **buffer=vorbis_analysis_buffer(&d_vd,chunks);
|
|
||||||
for(i=0;i<chunks;i++){
|
|
||||||
buffer[0][i]=((in[i*2+1]<<8)|
|
|
||||||
(0x00ff&(int)in[i*2]))/32768.f;
|
|
||||||
}
|
|
||||||
vorbis_analysis_wrote(&d_vd,i);
|
|
||||||
|
|
||||||
while(vorbis_analysis_blockout(&d_vd,&d_vb)==1){
|
|
||||||
vorbis_analysis(&d_vb,NULL);
|
|
||||||
vorbis_bitrate_addblock(&d_vb);
|
|
||||||
|
|
||||||
while(vorbis_bitrate_flushpacket(&d_vd,&d_op)){
|
|
||||||
|
|
||||||
ogg_stream_packetin(&d_os,&d_op);
|
|
||||||
int result = 1;
|
|
||||||
while(result){
|
|
||||||
int result=ogg_stream_pageout(&d_os,&d_og);
|
|
||||||
if(result==0)break;
|
|
||||||
fwrite(d_og.header,1,d_og.header_len,d_out);
|
|
||||||
fwrite(d_og.body,1,d_og.body_len,d_out);
|
|
||||||
if(ogg_page_eos(&d_og))result=1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return noutput_items;
|
|
||||||
}
|
|
||||||
|
|
||||||
} /* namespace satnogs */
|
|
||||||
} /* namespace gr */
|
|
|
@ -0,0 +1,137 @@
|
||||||
|
/* -*- c++ -*- */
|
||||||
|
/*
|
||||||
|
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017, Libre Space Foundation <http://librespacefoundation.org/>
|
||||||
|
*
|
||||||
|
* This program 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <gnuradio/io_signature.h>
|
||||||
|
#include "ogg_encoder_impl.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
namespace gr
|
||||||
|
{
|
||||||
|
namespace satnogs
|
||||||
|
{
|
||||||
|
|
||||||
|
ogg_encoder::sptr
|
||||||
|
ogg_encoder::make (char* filename, double samp_rate, float quality)
|
||||||
|
{
|
||||||
|
return gnuradio::get_initial_sptr (
|
||||||
|
new ogg_encoder_impl (filename, samp_rate, quality));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The private constructor
|
||||||
|
*/
|
||||||
|
ogg_encoder_impl::ogg_encoder_impl (char* filename, double samp_rate,
|
||||||
|
float quality) :
|
||||||
|
gr::sync_block ("ogg_encoder",
|
||||||
|
gr::io_signature::make (1, 1, sizeof(float)),
|
||||||
|
gr::io_signature::make (0, 0, 0))
|
||||||
|
{
|
||||||
|
d_quality = quality;
|
||||||
|
d_out = fopen (filename, "wb");
|
||||||
|
d_samp_rate = samp_rate;
|
||||||
|
vorbis_info_init (&d_vi);
|
||||||
|
int ret = vorbis_encode_init_vbr (&d_vi, 1, d_samp_rate, d_quality);
|
||||||
|
if (ret)
|
||||||
|
exit (1);
|
||||||
|
|
||||||
|
vorbis_comment_init (&d_vc);
|
||||||
|
vorbis_comment_add_tag (&d_vc, "ENCODER", "satnogs ogg encoder");
|
||||||
|
|
||||||
|
vorbis_analysis_init (&d_vd, &d_vi);
|
||||||
|
vorbis_block_init (&d_vd, &d_vb);
|
||||||
|
|
||||||
|
srand (time (NULL));
|
||||||
|
ogg_stream_init (&d_os, rand ());
|
||||||
|
|
||||||
|
ogg_packet header;
|
||||||
|
ogg_packet header_comm;
|
||||||
|
ogg_packet header_code;
|
||||||
|
|
||||||
|
vorbis_analysis_headerout (&d_vd, &d_vc, &header, &header_comm,
|
||||||
|
&header_code);
|
||||||
|
ogg_stream_packetin (&d_os, &header);
|
||||||
|
ogg_stream_packetin (&d_os, &header_comm);
|
||||||
|
ogg_stream_packetin (&d_os, &header_code);
|
||||||
|
int result = 1;
|
||||||
|
while (result) {
|
||||||
|
result = ogg_stream_flush (&d_os, &d_og);
|
||||||
|
if (result == 0)
|
||||||
|
break;
|
||||||
|
fwrite (d_og.header, 1, d_og.header_len, d_out);
|
||||||
|
fwrite (d_og.body, 1, d_og.body_len, d_out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ogg_encoder_impl::~ogg_encoder_impl ()
|
||||||
|
{
|
||||||
|
vorbis_analysis_wrote (&d_vd, 0);
|
||||||
|
ogg_stream_clear (&d_os);
|
||||||
|
vorbis_block_clear (&d_vb);
|
||||||
|
vorbis_dsp_clear (&d_vd);
|
||||||
|
vorbis_comment_clear (&d_vc);
|
||||||
|
vorbis_info_clear (&d_vi);
|
||||||
|
fclose (d_out);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ogg_encoder_impl::work (int noutput_items,
|
||||||
|
gr_vector_const_void_star &input_items,
|
||||||
|
gr_vector_void_star &output_items)
|
||||||
|
{
|
||||||
|
const char *in = (const char *) input_items[0];
|
||||||
|
int i;
|
||||||
|
float **buffer = vorbis_analysis_buffer (&d_vd, noutput_items);
|
||||||
|
memcpy(buffer[0], in, noutput_items * sizeof(float));
|
||||||
|
|
||||||
|
vorbis_analysis_wrote (&d_vd, noutput_items);
|
||||||
|
|
||||||
|
while (vorbis_analysis_blockout (&d_vd, &d_vb) == 1) {
|
||||||
|
vorbis_analysis (&d_vb, NULL);
|
||||||
|
vorbis_bitrate_addblock (&d_vb);
|
||||||
|
|
||||||
|
while (vorbis_bitrate_flushpacket (&d_vd, &d_op)) {
|
||||||
|
|
||||||
|
ogg_stream_packetin (&d_os, &d_op);
|
||||||
|
int result = 1;
|
||||||
|
while (result) {
|
||||||
|
int result = ogg_stream_pageout (&d_os, &d_og);
|
||||||
|
if (result == 0)
|
||||||
|
break;
|
||||||
|
fwrite (d_og.header, 1, d_og.header_len, d_out);
|
||||||
|
fwrite (d_og.body, 1, d_og.body_len, d_out);
|
||||||
|
if (ogg_page_eos (&d_og))
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return noutput_items;
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace satnogs */
|
||||||
|
} /* namespace gr */
|
|
@ -18,41 +18,42 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef INCLUDED_SATNOGS_OGG_ENCODER_IMPL_H
|
#ifndef INCLUDED_SATNOGS_OGG_ENCODER_IMPL_H
|
||||||
#define INCLUDED_SATNOGS_OGG_ENCODER_IMPL_H
|
#define INCLUDED_SATNOGS_OGG_ENCODER_IMPL_H
|
||||||
|
|
||||||
#include <satnogs/ogg_encoder.h>
|
#include <satnogs/ogg_encoder.h>
|
||||||
#include <vorbis/vorbisenc.h>
|
#include <vorbis/vorbisenc.h>
|
||||||
|
|
||||||
namespace gr {
|
namespace gr
|
||||||
namespace satnogs {
|
{
|
||||||
|
namespace satnogs
|
||||||
|
{
|
||||||
|
|
||||||
class ogg_encoder_impl : public ogg_encoder
|
class ogg_encoder_impl : public ogg_encoder
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Nothing to declare in this block.
|
// Nothing to declare in this block.
|
||||||
ogg_stream_state d_os;
|
ogg_stream_state d_os;
|
||||||
ogg_page d_og;
|
ogg_page d_og;
|
||||||
ogg_packet d_op;
|
ogg_packet d_op;
|
||||||
|
|
||||||
vorbis_info d_vi;
|
vorbis_info d_vi;
|
||||||
vorbis_comment d_vc;
|
vorbis_comment d_vc;
|
||||||
|
|
||||||
vorbis_dsp_state d_vd;
|
vorbis_dsp_state d_vd;
|
||||||
vorbis_block d_vb;
|
vorbis_block d_vb;
|
||||||
FILE* d_out;
|
FILE* d_out;
|
||||||
double d_samp_rate;
|
double d_samp_rate;
|
||||||
float d_quality;
|
float d_quality;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ogg_encoder_impl(char* filename, double samp_rate, float quality);
|
ogg_encoder_impl (char* filename, double samp_rate, float quality);
|
||||||
~ogg_encoder_impl();
|
~ogg_encoder_impl ();
|
||||||
|
|
||||||
// Where all the action really happens
|
// Where all the action really happens
|
||||||
int work(int noutput_items,
|
int
|
||||||
gr_vector_const_void_star &input_items,
|
work (int noutput_items, gr_vector_const_void_star &input_items,
|
||||||
gr_vector_void_star &output_items);
|
gr_vector_void_star &output_items);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace satnogs
|
} // namespace satnogs
|
|
@ -31,7 +31,7 @@
|
||||||
#include "satnogs/ax25_decoder_bm.h"
|
#include "satnogs/ax25_decoder_bm.h"
|
||||||
#include "satnogs/qb50_deframer.h"
|
#include "satnogs/qb50_deframer.h"
|
||||||
#include "satnogs/waterfall_sink.h"
|
#include "satnogs/waterfall_sink.h"
|
||||||
#include "satnogs/ogg_enc.h"
|
#include "satnogs/ogg_encoder.h"
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,5 +98,5 @@ GR_SWIG_BLOCK_MAGIC2(satnogs, qb50_deframer);
|
||||||
|
|
||||||
%include "satnogs/waterfall_sink.h"
|
%include "satnogs/waterfall_sink.h"
|
||||||
GR_SWIG_BLOCK_MAGIC2(satnogs, waterfall_sink);
|
GR_SWIG_BLOCK_MAGIC2(satnogs, waterfall_sink);
|
||||||
%include "satnogs/ogg_enc.h"
|
%include "satnogs/ogg_encoder.h"
|
||||||
GR_SWIG_BLOCK_MAGIC2(satnogs, ogg_enc);
|
GR_SWIG_BLOCK_MAGIC2(satnogs, ogg_encoder);
|
||||||
|
|
Loading…
Reference in New Issue