Recording and playing HARK std messages by rosbag

  • The purpose of this tutorial is to save and load bag files in HARK.
  • This tutorial provides the following two network files.
    • HarkWavePublisher.n : Record HarkWave messages to a bag file.
    • HarkWaveSaver.n : Receive the HarkWave messages from the bag file and save them as a raw file.

 

HarkWavePublisher.n

 Main Sheet Configuration

  • Required Modules
    • RosNodeGenerator
    • Constant
    • InputStream
    • MAIN_LOOP (Same as LOOP0 in the previous tutorials. This appears after you create iterator sheet.)

 

RosNodeGenerator

All description is available at Publishing/Subscribing msg type Topics.

 

Constant

All description is available at Application of publishing/subscribing HARK std messages.

 

InputStream

All description is available at Application of publishing/subscribing HARK std messages.

 

MAIN_LOOP

All description is available at Application of publishing/subscribing HARK std messages.

 

 Iterator Sheet Configuration

  • Required Modules
    • AudioStreamFromWave
    • RosHarkMsgsPublisher

 

AudioStreamFromWave

All description is available at Application of publishing/subscribing HARK std messages.

 

RosHarkMsgsPublisher

All description is available at Application of publishing/subscribing HARK std messages.

 

 Recording HarkWave messages to a bag file

Save the network file before closing [e.g.) HarkWavePublisher.n ]

Open a new terminal and type

roscore

 

Prepare one recorded wave file for the evaluation (YOUR_WAV.wav).

Go back to the previous terminal and run the HARK network file

./HarkWavePublisher.n YOUR_WAV.wav

 

Then the topic “/HarkWave” is published.
Open a new terminal and type

rosbag record /HarkWave

 

You can record the HarkWave message to a bag file.
You will find ***.bag in the current directory.

 

HarkWaveSaver.n

 Main Sheet Configuration

  • Required Modules
    • RosNodeGenerator
    • MAIN_LOOP (Same as LOOP0 in the previous tutorials. This appears after you create iterator sheet.)

 

RosNodeGenerator

All description is available at Publishing/Subscribing msg type Topics.

 

MAIN_LOOP

All description is available at Application of publishing/subscribing HARK std messages.

 

 Iterator Sheet Configuration

  • Required Modules
    • HarkMsgsStreamFromRos
    • ChannelSelector
    • SaveRawPCM

 

HarkMsgsStreamFromRos

  • Module Description

This module receives one of HarkMsgs and outputs them one-by-one frame-by-frame.
The output NOT_EOF can be the condition for the loop in the network file.
Therefore, this can be used exactly like AudioStreamFromWave.

 

  • Module Location
Node list > HARK:ROS:IO > HarkMsgsStreamFromRos

 

  • Property settings
Name Type Value Explanation
STREAM_SELECTION string HarkWave subscribed message type
TOPIC_NAME_HARKWAVE string HarkWave subscribed topic name
ROS_LOOP_RATE float 1000000 ROS loop frequency
MSG_BUFFER_NUM int 100 Number of buffers taken by ROS
DATA_BUFFER_NUM int 100 Number of buffers taken by HARK
KILL_TIME_LEN int 900000 Life duration of the network file for no data reception [usec]
KILL_NETWORK bool true Enable kill function for no data reception
ENABLE_DEBUG bool false Enable debug print

 

ChannelSelector

  • Module Description

This module extract the desired channel signals from multichannel wave signal.

 

  • Module Location
Node list > HARK:MISC > ChannelSelector

 

  • Property settings
Name Type Value Explanation
SELECTOR object <Vector<int> 0> Selection of the channel. Here only channel 0 is selected.

 

SaveRawPCM

  • Module Description

This module saves the raw signal into a certain sw file.

 

  • Module Location
Node list > HARK:AudioIO > SaveRawPCM

 

  • Property settings
Name Type Value Explanation
BASENAME string sep_ Base name of the saved file. Here the file name will be “sep_0.sw” “sep_1.sw”…
ADVANCE int 160 Shift length
BITS int 16 Bit depth of the saved data

 

  • Terminal settings

Set “OUTPUT” for this output.

 

 Receiving bag file messages and saves them as a wave file

Save the network file before closing [e.g.) HarkWaveSaver.n ]

Open a new terminal and type

roscore

 

Go back to the previous terminal and run the HARK network file

./HarkWaveSaver.n

 

Then the network file starts to wait for HarkWave messages.
Open a new terminal and type

rosbag play ***.bag

 

Here, ***.bag is the bag file you recorded in the previous section.
When the network file receives the HarkWave message from the bag file, it starts to save them as a raw file named “sep_.sw”.
After the bag file is finished, the HARK network file is automatically killed 900000[usec] later.
You will see there is a seved “sep_.sw” in the current directory.

Let’s play “sep_.sw”. Before that we need to convert it to a wave file by the following command.

sox -e signed-integer -c 1 -r 16000 -t sw sep_.sw -t wav sample.wav

 

Play the sample.wav.

play sample.wav

 

You may hear the same sound as YOUR_WAV.wav.

Back to Top