Here's an example that generates a wave file that is playable by both gnuradio and mplayer
On Tue, Jun 9, 2015 at 2:49 PM, Fernando <[email protected]> wrote: > You can address me by Fernando, it's easier to pronounce ;-) > I'm trying to save audio from the audio source to a file or from a signal > source 1Khz for instance. > I've tryed different things, and different data rate (I've tried 44100 also) > and is always the same eror > > Generating: "/home/ubuntu/top_block.py" > > Executing: "/home/ubuntu/top_block.py" > > Traceback (most recent call last): > File "/home/ubuntu/top_block.py", line 51, in <module> > tb = top_block() > File "/home/ubuntu/top_block.py", line 33, in __init__ > self.blocks_wavfile_source_0 = > blocks.wavfile_source("/home/ubuntu/prueba.wav", True) > File > "/usr/local/lib/python2.7/dist-packages/gnuradio/blocks/blocks_swig0.py", > line 1418, in make > return _blocks_swig0.wavfile_source_make(*args, **kwargs) > RuntimeError: WAV file does not contain any samples > >>>> Done > > > But i have converted a mp3 file to wav with mpg123 and the file plays well > using wav file source. > Moreover: i've converted a file with mpg123 to a wav file at 22Ksps and it > works too. > And The file wav generated in gnuradio with wav file source is a valid wav > file which I can play with amarok. > So the problem is that wav file source does not recognice the files created > by wav file sink altough they seem to be fully valid files. > > > regards > > > > > > > > > > > Marcus Müller-3 wrote >> Hi fffdddoo (is that really the name by which we should address you?), >> >> I'm guessing you try to save audio directly from the audio source to a >> wav file, right? >> >> So, my blind guess is that Baokum wrongly configured the audio source >> and simply nothing came out of it. >> For example, no soundcard normally uses a sampling rate of 32kHz. A >> typical rate is 44.1kHz. >> >> You might want to check your console output for errors. Most of the >> time, the audio sink complains about things like the device name not >> working or something else going wrong; this all depends very much on >> which operating system you use GNU Radio. >> Do you get any errors? >> >> Of course, when using a file_sink you don't generate a wav file, that's >> why we have the WAV sink :) >> >> Best regards, >> Marcus >> >> On 06/09/2015 09:34 PM, fffdddooo wrote: >>> Well. I read the workaround. The problem is if you use file source and >>> file >>> sink instead of wav file source and wav file sink, you are not generating >>> a >>> wav file. You can name it *.wav, but it isn't a wav file at all. >>> What I want to do is generating a wav file wich can be playd with any wav >>> player (that I can do with wav file sink) and been able to use it again >>> in >>> gnu radio (wich does not work with file wav file source). >>> I've tried 8 and 16 bits and different data rate >>> >>> >>> >>> >>> >>> Marcus Müller-3 wrote >>>> Hi fffdddooo, >>>> >>>> Baokum Liu asked that two years ago. Some things have changed since >>>> then; do you have a question that we might help you answer? >>>> >>>> Best regards, >>>> Marcus >>>> >>>> On 06/09/2015 08:46 PM, fffdddooo wrote: >>>>> Did you find the solution? >>>>> >>>>> regards >>>>> >>>>> Baokun Liu wrote >>>>>> Hi guys, >>>>>> >>>>>> I am playing with gnuradio companion. I have a question on wav file. >>>>>> >>>>>> I play like this first (the samp_rate set to 32k) >>>>>> >>>>>> *Audio Source ---> Wav File Sink;* >>>>>> >>>>>> I save the file as test.wav. It sound well. >>>>>> >>>>>> Then, I play the file back (samp_rate is 32k). >>>>>> >>>>>> *Wave File Source ---> Audio Sink; * >>>>>> >>>>>> The error comes as: WAV file does not contain any samples. >>>>>> >>>>>> Could anyone point out the problem? How could I use the 'wav file >>>>>> source' >>>>>> block? >>>>>> >>>>>> Thanks, >>>>>> >>>>>> Baokun >>>>>> >>>>>> _______________________________________________ >>>>>> Discuss-gnuradio mailing list >>>>>> Discuss-gnuradio@ >>>>>> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio >>>>> >>>>> >>>>> >>>>> -- >>>>> View this message in context: >>>>> http://gnuradio.4.n7.nabble.com/wav-file-source-question-tp42578p54103.html >>>>> Sent from the GnuRadio mailing list archive at Nabble.com. >>>>> >>>>> _______________________________________________ >>>>> Discuss-gnuradio mailing list >>>>> >>>> Discuss-gnuradio@ >>>>> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio >>>> >>>> _______________________________________________ >>>> Discuss-gnuradio mailing list >>>> Discuss-gnuradio@ >>>> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio >>> >>> >>> >>> >>> -- >>> View this message in context: >>> http://gnuradio.4.n7.nabble.com/wav-file-source-question-tp42578p54105.html >>> Sent from the GnuRadio mailing list archive at Nabble.com. >>> >>> _______________________________________________ >>> Discuss-gnuradio mailing list >>> > >> Discuss-gnuradio@ > >>> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio >> >> >> _______________________________________________ >> Discuss-gnuradio mailing list > >> Discuss-gnuradio@ > >> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio > > > > > > -- > View this message in context: > http://gnuradio.4.n7.nabble.com/wav-file-source-question-tp42578p54111.html > Sent from the GnuRadio mailing list archive at Nabble.com. > > _______________________________________________ > Discuss-gnuradio mailing list > [email protected] > https://lists.gnu.org/mailman/listinfo/discuss-gnuradio -- GDB has a 'break' feature; why doesn't it have 'fix' too?
#!/usr/bin/env python2
##################################################
# GNU Radio Python Flow Graph
# Title: Wav Generator
# Generated: Tue Jun 9 16:21:49 2015
##################################################
from gnuradio import analog
from gnuradio import audio
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
class wav_generator(gr.top_block):
def __init__(self):
gr.top_block.__init__(self, "Wav Generator")
##################################################
# Variables
##################################################
self.samp_rate = samp_rate = 44100
self.f440 = f440 = 440
self.f350 = f350 = 350
self.duration = duration = 2.5
##################################################
# Blocks
##################################################
self.blocks_wavfile_sink_0 = blocks.wavfile_sink("/tmp/wavfile.wav", 1, samp_rate, 8)
self.blocks_head_0 = blocks.head(gr.sizeof_float*1, int(duration * samp_rate))
self.blocks_add_xx_0 = blocks.add_vff(1)
self.audio_sink_0 = audio.sink(samp_rate, "", True)
self.analog_sig_source_x_1 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, f440, 0.4, 0)
self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, f350, 0.4, 0)
##################################################
# Connections
##################################################
self.connect((self.analog_sig_source_x_0, 0), (self.blocks_add_xx_0, 0))
self.connect((self.analog_sig_source_x_1, 0), (self.blocks_add_xx_0, 1))
self.connect((self.blocks_add_xx_0, 0), (self.blocks_head_0, 0))
self.connect((self.blocks_head_0, 0), (self.audio_sink_0, 0))
self.connect((self.blocks_head_0, 0), (self.blocks_wavfile_sink_0, 0))
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
self.analog_sig_source_x_0.set_sampling_freq(self.samp_rate)
self.analog_sig_source_x_1.set_sampling_freq(self.samp_rate)
self.blocks_head_0.set_length(int(self.duration * self.samp_rate))
def get_f440(self):
return self.f440
def set_f440(self, f440):
self.f440 = f440
self.analog_sig_source_x_1.set_frequency(self.f440)
def get_f350(self):
return self.f350
def set_f350(self, f350):
self.f350 = f350
self.analog_sig_source_x_0.set_frequency(self.f350)
def get_duration(self):
return self.duration
def set_duration(self, duration):
self.duration = duration
self.blocks_head_0.set_length(int(self.duration * self.samp_rate))
if __name__ == '__main__':
parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
(options, args) = parser.parse_args()
tb = wav_generator()
tb.start()
tb.wait()
#!/usr/bin/env python2
##################################################
# GNU Radio Python Flow Graph
# Title: Wav Playback
# Generated: Tue Jun 9 16:22:19 2015
##################################################
from gnuradio import audio
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
class wav_playback(gr.top_block):
def __init__(self):
gr.top_block.__init__(self, "Wav Playback")
##################################################
# Variables
##################################################
self.samp_rate = samp_rate = 44100
self.duration = duration = 2.5
##################################################
# Blocks
##################################################
self.blocks_wavfile_source_0_0 = blocks.wavfile_source("/tmp/wavfile.wav", False)
self.audio_sink_0_0 = audio.sink(samp_rate, "", True)
##################################################
# Connections
##################################################
self.connect((self.blocks_wavfile_source_0_0, 0), (self.audio_sink_0_0, 0))
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
def get_duration(self):
return self.duration
def set_duration(self, duration):
self.duration = duration
if __name__ == '__main__':
parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
(options, args) = parser.parse_args()
tb = wav_playback()
tb.start()
tb.wait()
wavfile.grc
Description: Binary data
_______________________________________________ Discuss-gnuradio mailing list [email protected] https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
