MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TEST

Function TEST

tensorflow/core/kernels/decode_wav_op_test.cc:38–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36namespace {
37
38TEST(DecodeWavOpTest, DecodeWavTest) {
39 Scope root = Scope::NewRootScope();
40
41 std::vector<uint8> wav_data = {
42 'R', 'I', 'F', 'F', 44, 0, 0, 0, // size of whole file - 8
43 'W', 'A', 'V', 'E', 'f', 'm', 't', ' ', 16, 0, 0,
44 0, // size of fmt block - 8: 24 - 8
45 1, 0, // format: PCM (1)
46 1, 0, // channels: 1
47 0x13, 0x37, 0, 0, // sample rate: 14099
48 0x26, 0x6e, 0, 0, // byte rate: 2 * 14099
49 2, 0, // block align: NumChannels * BytesPerSample
50 16, 0, // bits per sample: 2 * 8
51 'd', 'a', 't', 'a', 8, 0, 0, 0, // size of payload: 8
52 0, 0, // first sample: 0
53 0xff, 0x3f, // second sample: 16383
54 0xff, 0x7f, // third sample: 32767 (saturated)
55 0x00, 0x80, // fourth sample: -32768 (saturated)
56 };
57 Tensor content_tensor =
58 test::AsScalar<tstring>(string(wav_data.begin(), wav_data.end()));
59 Output content_op =
60 Const(root.WithOpName("content_op"), Input::Initializer(content_tensor));
61
62 DecodeWav decode_wav_op =
63 DecodeWav(root.WithOpName("decode_wav_op"), content_op);
64
65 TF_ASSERT_OK(root.status());
66
67 ClientSession session(root);
68 std::vector<Tensor> outputs;
69
70 TF_EXPECT_OK(session.Run(ClientSession::FeedType(),
71 {decode_wav_op.audio, decode_wav_op.sample_rate},
72 &outputs));
73
74 const Tensor& audio = outputs[0];
75 const int sample_rate = outputs[1].flat<int32>()(0);
76
77 EXPECT_EQ(2, audio.dims());
78 EXPECT_EQ(1, audio.dim_size(1));
79 EXPECT_EQ(4, audio.dim_size(0));
80 EXPECT_NEAR(0.0f, audio.flat<float>()(0), 1e-4f);
81 EXPECT_NEAR(0.5f, audio.flat<float>()(1), 1e-4f);
82 EXPECT_NEAR(1.0f, audio.flat<float>()(2), 1e-4f);
83 EXPECT_NEAR(-1.0f, audio.flat<float>()(3), 1e-4f);
84 EXPECT_EQ(14099, sample_rate);
85}
86
87TEST(DecodeWavOpTest, DecodeWav_ShapeFn) {
88 ShapeInferenceTestOp op("DecodeWav");

Callers

nothing calls this directly

Calls 14

DecodeWavFunction · 0.85
NodeDefBuilderClass · 0.85
WithOpNameMethod · 0.80
ConstFunction · 0.50
InitializerClass · 0.50
beginMethod · 0.45
endMethod · 0.45
statusMethod · 0.45
RunMethod · 0.45
dimsMethod · 0.45
dim_sizeMethod · 0.45
FinalizeMethod · 0.45

Tested by

no test coverage detected