You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

audio_ops.h 4.0 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**
  2. * Copyright 2019-2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef GE_OP_AUDIO_OPS_H_
  17. #define GE_OP_AUDIO_OPS_H_
  18. #include "graph/operator_reg.h"
  19. namespace ge {
  20. /**
  21. *@brief Mel-Frequency Cepstral Coefficient (MFCC) calculation consists of \n
  22. taking the DCT-II of a log-magnitude mel-scale spectrogram.
  23. *@par Inputs:
  24. *Input "spectrogram" is a 3D tensor. Input "sample_rate" is a scalar. \n
  25. * @li spectrogram: A 3D float tensor.
  26. * @li sample_rate: The MFCC sample rate.
  27. *@par Attributes:
  28. *@li upper_frequency_limit: The highest frequency for calculation.
  29. *@li lower_frequency_limit: The lowest frequency for calculation.
  30. *@li filterbank_channel_count: Resolution of the Mel bank.
  31. *@li dct_coefficient_count: Number of output channels to produce \n
  32. per time slice.
  33. *@par Outputs:
  34. *y: A Tensor of type float32.
  35. *@attention Constraints: \n
  36. *Mfcc runs on the Ascend AI CPU, which delivers poor performance. \n
  37. */
  38. REG_OP(Mfcc)
  39. .INPUT(spectrogram, TensorType({DT_FLOAT}))
  40. .INPUT(sample_rate, TensorType({DT_INT32}))
  41. .OUTPUT(y, TensorType({DT_FLOAT}))
  42. .ATTR(upper_frequency_limit, Float, 4000)
  43. .ATTR(lower_frequency_limit, Float, 20)
  44. .ATTR(filterbank_channel_count, Int, 40)
  45. .ATTR(dct_coefficient_count, Int, 13)
  46. .OP_END_FACTORY_REG(Mfcc)
  47. /**
  48. *@brief Decodes and generates spectrogram using wav float tensor.
  49. *@par Inputs:
  50. *Input "x" is a 2D matrix. \n
  51. * x: A float tensor. Float representation of audio data.
  52. *@par Attributes:
  53. *@li window_size: Size of the spectrogram window.
  54. *@li stride: Size of the spectrogram stride.
  55. *@li magnitude_squared: If true, uses squared magnitude.
  56. *@par Outputs:
  57. *spectrogram: A 3D float Tensor.
  58. *@attention Constraints: \n
  59. *AudioSpectrogram runs on the Ascend AI CPU, which delivers \n
  60. poor performance.
  61. */
  62. REG_OP(AudioSpectrogram)
  63. .INPUT(x, TensorType({DT_FLOAT}))
  64. .OUTPUT(spectrogram, TensorType({DT_FLOAT}))
  65. .REQUIRED_ATTR(window_size, Int)
  66. .REQUIRED_ATTR(stride, Int)
  67. .ATTR(magnitude_squared, Bool, false)
  68. .OP_END_FACTORY_REG(AudioSpectrogram)
  69. /**
  70. *@brief Decodes a 16-bit WAV file into a float tensor.
  71. *@par Inputs:
  72. *contents: A Tensor of type string. The WAV-encoded audio, usually from a file.
  73. *@par Attributes:
  74. *@li desired_channels: An optional int. Defaults to "-1". \n
  75. Number of sample channels wanted.
  76. *@li desired_samples: An optional int. Defaults to "-1". \n
  77. Length of audio requested.
  78. *@par Outputs:
  79. *@li *audio: A Tensor of type float32.
  80. *@li *sample_rate: A Tensor of type int32.
  81. *@attention Constraints: \n
  82. *DecodeWav runs on the Ascend AI CPU, which delivers poor performance. \n
  83. */
  84. REG_OP(DecodeWav)
  85. .INPUT(contents, TensorType({DT_STRING}))
  86. .OUTPUT(audio, TensorType({DT_FLOAT}))
  87. .OUTPUT(sample_rate, TensorType({DT_INT32}))
  88. .ATTR(desired_channels, Int, -1)
  89. .ATTR(desired_samples, Int, -1)
  90. .OP_END_FACTORY_REG(DecodeWav)
  91. /**
  92. *@brief Encode audio data using the WAV file format.
  93. *@par Inputs:
  94. *Including: \n
  95. * @li audio: A Tensor of type DT_FLOAT.
  96. * @li sample_rate: A Tensor of type DT_INT32.
  97. *@par Outputs:
  98. *contents: A Tensor of type DT_STRING.
  99. *@attention Constraints:\n
  100. *EncodeWav runs on the Ascend AI CPU, which delivers poor performance.\n
  101. */
  102. REG_OP(EncodeWav)
  103. .INPUT(audio, TensorType({DT_FLOAT}))
  104. .INPUT(sample_rate, TensorType({DT_INT32}))
  105. .OUTPUT(contents, TensorType({DT_STRING}))
  106. .OP_END_FACTORY_REG(EncodeWav)
  107. } // namespace ge
  108. #endif // GE_OP_AUDIO_OPS_H_

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示